[svn-commits] anthonyl: branch anthonyl/8350-codec r47757 - in /team/anthonyl/8350-codec: a...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Thu Nov 16 13:09:05 MST 2006


Author: anthonyl
Date: Thu Nov 16 14:09:04 2006
New Revision: 47757

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47757
Log:
added some verbose debugging to help assist with pinpoint where to impliment my fix

Modified:
    team/anthonyl/8350-codec/apps/app_dial.c
    team/anthonyl/8350-codec/channels/chan_sip.c

Modified: team/anthonyl/8350-codec/apps/app_dial.c
URL: http://svn.digium.com/view/asterisk/team/anthonyl/8350-codec/apps/app_dial.c?view=diff&rev=47757&r1=47756&r2=47757
==============================================================================
--- team/anthonyl/8350-codec/apps/app_dial.c (original)
+++ team/anthonyl/8350-codec/apps/app_dial.c Thu Nov 16 14:09:04 2006
@@ -21,7 +21,7 @@
  * \brief dial() & retrydial() - Trivial application to dial a channel and send an URL on answer
  *
  * \author Mark Spencer <markster at digium.com>
- * 
+ *
  * \ingroup applications
  */
 
@@ -78,10 +78,10 @@
 "continue if no requested channels can be called, or if the timeout expires.\n\n"
 "  This application sets the following channel variables upon completion:\n"
 "    DIALEDTIME   - This is the time from dialing a channel until when it\n"
-"                   is disconnected.\n" 
+"                   is disconnected.\n"
 "    ANSWEREDTIME - This is the amount of time for actual call.\n"
 "    DIALSTATUS   - This is the status of the call:\n"
-"                   CHANUNAVAIL | CONGESTION | NOANSWER | BUSY | ANSWER | CANCEL\n" 
+"                   CHANUNAVAIL | CONGESTION | NOANSWER | BUSY | ANSWER | CANCEL\n"
 "                   DONTCALL | TORTURE\n"
 "  For the Privacy and Screening Modes, the DIALSTATUS variable will be set to\n"
 "DONTCALL if the called party chooses to send the calling party to the 'Go Away'\n"
@@ -104,7 +104,7 @@
 "           party has answered, but before the call gets bridged. The 'called'\n"
 "           DTMF string is sent to the called party, and the 'calling' DTMF\n"
 "           string is sent to the calling party. Both parameters can be used\n"
-"           alone.\n"  	
+"           alone.\n"
 "    f    - Force the callerid of the *calling* channel to be set as the\n"
 "           extension associated with the channel using a dialplan 'hint'.\n"
 "           For example, some PSTNs do not allow CallerID to be set to anything\n"
@@ -115,7 +115,7 @@
 "           the specified priority and the called party to the specified priority+1.\n"
 "           Optionally, an extension, or extension and context may be specified. \n"
 "           Otherwise, the current extension is used. You cannot use any additional\n"
-"           action post answer options in conjunction with this option.\n" 
+"           action post answer options in conjunction with this option.\n"
 "    h    - Allow the called party to hang up by sending the '*' DTMF digit.\n"
 "    H    - Allow the calling party to hang up by hitting the '*' DTMF digit.\n"
 "    i    - Asterisk will ignore any forwarding requests it may receive on this\n"
@@ -138,7 +138,7 @@
 "    M(x[^arg]) - Execute the Macro for the *called* channel before connecting\n"
 "           to the calling channel. Arguments can be specified to the Macro\n"
 "           using '^' as a delimeter. The Macro can set the variable\n"
-"           MACRO_RESULT to specify the following actions after the Macro is\n" 
+"           MACRO_RESULT to specify the following actions after the Macro is\n"
 "           finished executing.\n"
 "           * ABORT        Hangup both legs of the call.\n"
 "           * CONGESTION   Behave as if line congestion was encountered.\n"
@@ -179,7 +179,7 @@
 "    r    - Indicate ringing to the calling party. Pass no audio to the calling\n"
 "           party until the called channel has answered.\n"
 "    S(x) - Hang up the call after 'x' seconds *after* the called party has\n"
-"           answered the call.\n"  	
+"           answered the call.\n"
 "    t    - Allow the called party to transfer the calling party by sending the\n"
 "           DTMF sequence defined in features.conf.\n"
 "    T    - Allow the calling party to transfer the called party by sending the\n"
@@ -368,7 +368,7 @@
 		s = (new_val);		\
 	} while (0)
 
-static int onedigit_goto(struct ast_channel *chan, const char *context, char exten, int pri) 
+static int onedigit_goto(struct ast_channel *chan, const char *context, char exten, int pri)
 {
 	char rexten[2] = { exten, '\0' };
 
@@ -397,7 +397,7 @@
 
 static void senddialevent(struct ast_channel *src, struct ast_channel *dst)
 {
-	manager_event(EVENT_FLAG_CALL, "Dial", 
+	manager_event(EVENT_FLAG_CALL, "Dial",
 			   "SubEvent: Begin\r\n"
 			   "Source: %s\r\n"
 			   "Destination: %s\r\n"
@@ -417,7 +417,7 @@
 					"Channel: %s\r\n"
 					"DialStatus: %s\r\n",
 					src->name, dialstatus);
-}	
+}
 
 /* helper function for wait_for_answer() */
 static void do_forward(struct dial_localuser *o,
@@ -466,7 +466,7 @@
 		c = o->chan = NULL;
 	}
 	if (!c) {
-		ast_clear_flag(o, DIAL_STILLGOING);	
+		ast_clear_flag(o, DIAL_STILLGOING);
 		handle_cause(cause, num);
 	} else {
 		char *new_cid_num, *new_cid_name;
@@ -493,7 +493,7 @@
 		S_REPLACE(c->cid.cid_rdnis, ast_strdup(S_OR(in->macroexten, in->exten)));
 		if (ast_call(c, tmpchan, 0)) {
 			ast_log(LOG_NOTICE, "Failed to dial on local channel for call forward to '%s'\n", tmpchan);
-			ast_clear_flag(o, DIAL_STILLGOING);	
+			ast_clear_flag(o, DIAL_STILLGOING);
 			ast_hangup(c);
 			c = o->chan = NULL;
 			num->nochan++;
@@ -530,15 +530,15 @@
 	struct ast_channel *peer = NULL;
 	/* single is set if only one destination is enabled */
 	int single = outgoing && !outgoing->next && !ast_test_flag(outgoing, OPT_MUSICBACK | OPT_RINGBACK);
-	
+
 	if (single) {
 		/* Turn off hold music, etc */
 		ast_deactivate_generator(in);
 		/* If we are calling a single channel, make them compatible for in-band tone purpose */
 		ast_channel_make_compatible(outgoing->chan, in);
 	}
-	
-	
+
+
 	while (*to && !peer) {
 		struct dial_localuser *o;
 		int pos = 0;	/* how many channels do we handle */
@@ -558,7 +558,7 @@
 				if (option_verbose > 2)
 					ast_verbose( VERBOSE_PREFIX_2 "Everyone is busy/congested at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan);
 				if (num.busy)
-					strcpy(pa->status, "BUSY");	
+					strcpy(pa->status, "BUSY");
 				else if (num.congestion)
 					strcpy(pa->status, "CONGESTION");
 				else if (num.nochan)
@@ -640,7 +640,7 @@
 					in->hangupcause = c->hangupcause;
 					ast_hangup(c);
 					c = o->chan = NULL;
-					ast_clear_flag(o, DIAL_STILLGOING);	
+					ast_clear_flag(o, DIAL_STILLGOING);
 					handle_cause(AST_CAUSE_BUSY, &num);
 					break;
 				case AST_CONTROL_CONGESTION:
@@ -714,7 +714,7 @@
 			} else if (single) {
 				/* XXX are we sure the logic is correct ? or we should just switch on f->frametype ? */
 				if (f->frametype == AST_FRAME_VOICE && !ast_test_flag(outgoing, OPT_RINGBACK|OPT_MUSICBACK)) {
-					if (ast_write(in, f)) 
+					if (ast_write(in, f))
 						ast_log(LOG_WARNING, "Unable to forward voice frame\n");
 				} else if (f->frametype == AST_FRAME_IMAGE && !ast_test_flag(outgoing, OPT_RINGBACK|OPT_MUSICBACK)) {
 					if (ast_write(in, f))
@@ -761,7 +761,7 @@
 					}
 				}
 
-				if (ast_test_flag(peerflags, OPT_CALLER_HANGUP) && 
+				if (ast_test_flag(peerflags, OPT_CALLER_HANGUP) &&
 						  (f->subclass == '*')) { /* hmm it it not guaranteed to be '*' anymore. */
 					if (option_verbose > 2)
 						ast_verbose(VERBOSE_PREFIX_3 "User hit %c to disconnect call.\n", f->subclass);
@@ -773,18 +773,18 @@
 			}
 
 			/* Forward HTML stuff */
-			if (single && (f->frametype == AST_FRAME_HTML) && !ast_test_flag(outgoing, DIAL_NOFORWARDHTML)) 
+			if (single && (f->frametype == AST_FRAME_HTML) && !ast_test_flag(outgoing, DIAL_NOFORWARDHTML))
 				if(ast_channel_sendhtml(outgoing->chan, f->subclass, f->data, f->datalen) == -1)
 					ast_log(LOG_WARNING, "Unable to send URL\n");
-			
+
 
 			if (single && ((f->frametype == AST_FRAME_VOICE) || (f->frametype == AST_FRAME_DTMF)))  {
 				if (ast_write(outgoing->chan, f))
 					ast_log(LOG_WARNING, "Unable to forward voice\n");
 			}
-			if (single && (f->frametype == AST_FRAME_CONTROL) && 
-				((f->subclass == AST_CONTROL_HOLD) || 
-				 (f->subclass == AST_CONTROL_UNHOLD) || 
+			if (single && (f->frametype == AST_FRAME_CONTROL) &&
+				((f->subclass == AST_CONTROL_HOLD) ||
+				 (f->subclass == AST_CONTROL_UNHOLD) ||
 				 (f->subclass == AST_CONTROL_VIDUPDATE))) {
 				if (option_verbose > 2)
 					ast_verbose(VERBOSE_PREFIX_3 "%s requested special control %d, passing it to %s\n", in->name, f->subclass, outgoing->chan->name);
@@ -869,13 +869,13 @@
 
 	var = pbx_builtin_getvar_helper(chan,"LIMIT_PLAYAUDIO_CALLER");
 	play_to_caller = var ? ast_true(var) : 1;
-	
+
 	var = pbx_builtin_getvar_helper(chan,"LIMIT_PLAYAUDIO_CALLEE");
 	play_to_callee = var ? ast_true(var) : 0;
-	
+
 	if (!play_to_caller && !play_to_callee)
 		play_to_caller = 1;
-	
+
 	var = pbx_builtin_getvar_helper(chan,"LIMIT_WARNING_FILE");
 	config->warning_sound = S_OR(var, "timeleft");
 
@@ -924,11 +924,11 @@
 	int res2;
 	int loopcount = 0;
 
-	/* Get the user's intro, store it in priv-callerintros/$CID, 
-	   unless it is already there-- this should be done before the 
+	/* Get the user's intro, store it in priv-callerintros/$CID,
+	   unless it is already there-- this should be done before the
 	   call is actually dialed  */
 
-	/* all ring indications and moh for the caller has been halted as soon as the 
+	/* all ring indications and moh for the caller has been halted as soon as the
 	   target extension was picked up. We are going to have to kill some
 	   time and make the caller believe the peer hasn't picked up yet */
 
@@ -950,7 +950,7 @@
 			res2 = ast_play_and_wait(peer,"priv-callpending");
 		if (!valid_priv_reply(opts, res2))
 			res2 = 0;
-		/* priv-callpending script: 
+		/* priv-callpending script:
 		   "I have a caller waiting, who introduces themselves as:"
 		*/
 		if (!res2)
@@ -969,7 +969,7 @@
 		\par priv-callee-options script:
 			"Dial 1 if you wish this caller to reach you directly in the future,
 				and immediately connect to their incoming call
-			 Dial 2 if you wish to send this caller to voicemail now and 
+			 Dial 2 if you wish to send this caller to voicemail now and
 				forevermore.
 			 Dial 3 to send this caller to the torture menus, now and forevermore.
 			 Dial 4 to send this caller to a simple "go away" menu, now and forevermore.
@@ -1033,7 +1033,7 @@
 	}
 
 	if (res2 == '1') {	/* the only case where we actually connect */
-		/* if the intro is NOCALLERID, then there's no reason to leave it on disk, it'll 
+		/* if the intro is NOCALLERID, then there's no reason to leave it on disk, it'll
 		   just clog things up, and it's not useful information, not being tied to a CID */
 		if( strncmp(pa->privcid,"NOCALLERID",10) == 0 || ast_test_flag(opts, OPT_SCREEN_NOINTRO) ) {
 			ast_filedelete(pa->privintro, NULL);
@@ -1111,7 +1111,7 @@
 		if (option_verbose > 2)
 			ast_verbose(VERBOSE_PREFIX_3 "Setting operator services mode to %d.\n", opermode);
 	}
-	
+
 	if (ast_test_flag(&opts, OPT_DURATION_STOP) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_STOP])) {
 		calldurationlimit = atoi(opt_args[OPT_ARG_DURATION_STOP]);
 		if (!calldurationlimit) {
@@ -1168,10 +1168,10 @@
 			l = callerid;
 			pa.privdb_val = AST_PRIVACY_UNKNOWN;
 		}
-		
+
 		ast_copy_string(pa.privcid,l,sizeof(pa.privcid));
 
-		if( strncmp(pa.privcid,"NOCALLERID",10) != 0 && ast_test_flag(&opts, OPT_SCREEN_NOCLID) ) { /* if callerid is set, and ast_test_flag(&opts, OPT_SCREEN_NOCLID) is set also */  
+		if( strncmp(pa.privcid,"NOCALLERID",10) != 0 && ast_test_flag(&opts, OPT_SCREEN_NOCLID) ) { /* if callerid is set, and ast_test_flag(&opts, OPT_SCREEN_NOCLID) is set also */
 			if (option_verbose > 2)
 				ast_verbose( VERBOSE_PREFIX_3  "CallerID set (%s); N option set; Screening should be off\n", pa.privcid);
 			pa.privdb_val = AST_PRIVACY_ALLOW;
@@ -1180,7 +1180,7 @@
 			if (option_verbose > 2)
 				ast_verbose( VERBOSE_PREFIX_3  "CallerID blank; N option set; Screening should happen; dbval is %d\n", pa.privdb_val);
 		}
-		
+
 		if(pa.privdb_val == AST_PRIVACY_DENY ) {
 			ast_copy_string(pa.status, "NOANSWER", sizeof(pa.status));
 			if (option_verbose > 2)
@@ -1205,8 +1205,8 @@
 			goto out; /* is this right??? */
 		}
 		else if(pa.privdb_val == AST_PRIVACY_UNKNOWN ) {
-			/* Get the user's intro, store it in priv-callerintros/$CID, 
-			   unless it is already there-- this should be done before the 
+			/* Get the user's intro, store it in priv-callerintros/$CID,
+			   unless it is already there-- this should be done before the
 			   call is actually dialed  */
 
 			/* make sure the priv-callerintros dir actually exists */
@@ -1274,10 +1274,11 @@
 				       OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR |
 				       OPT_CALLEE_PARK | OPT_CALLER_PARK |
 				       OPT_RINGBACK | OPT_MUSICBACK | OPT_FORCECLID);
-			ast_set2_flag(tmp, args.url, DIAL_NOFORWARDHTML);	
+			ast_set2_flag(tmp, args.url, DIAL_NOFORWARDHTML);
 		}
 		ast_copy_string(numsubst, number, sizeof(numsubst));
 		/* Request the peer */
+		ast_verbose("1. calling ast_request from dial: native: %s jointcodecs %s\n", ast_getformatname_multiple(buf, BUFSIZ, chan->nativeformats), ast_getformatname_multiple(buf, BUFSIZ, chan->jointcapability)  );
 		tmp->chan = ast_request(tech, chan->nativeformats, numsubst, &cause);
 		if (!tmp->chan) {
 			/* If we can't, just go on to the next call */
@@ -1334,7 +1335,7 @@
 
 		/* Setup outgoing SDP to match incoming one */
 		ast_rtp_make_compatible(tmp->chan, chan, !outgoing && !rest);
-		
+
 		/* Inherit specially named variables from parent channel */
 		ast_channel_inherit_variables(chan, tmp->chan);
 
@@ -1346,7 +1347,7 @@
 		S_REPLACE(tmp->chan->cid.cid_name, ast_strdup(chan->cid.cid_name));
 		S_REPLACE(tmp->chan->cid.cid_ani, ast_strdup(chan->cid.cid_ani));
 		S_REPLACE(tmp->chan->cid.cid_rdnis, ast_strdup(chan->cid.cid_rdnis));
-		
+
 		/* Copy language from incoming to outgoing */
 		ast_string_field_set(tmp->chan, language, chan->language);
 		ast_string_field_set(tmp->chan, accountcode, chan->accountcode);
@@ -1396,17 +1397,17 @@
 			if (!ast_test_flag(peerflags, OPT_ORIGINAL_CLID))
 				ast_set_callerid(tmp->chan, S_OR(chan->macroexten, chan->exten), get_cid_name(cidname, sizeof(cidname), chan), NULL);
 		}
-		/* Put them in the list of outgoing thingies...  We're ready now. 
+		/* Put them in the list of outgoing thingies...  We're ready now.
 		   XXX If we're forcibly removed, these outgoing calls won't get
 		   hung up XXX */
-		ast_set_flag(tmp, DIAL_STILLGOING);	
+		ast_set_flag(tmp, DIAL_STILLGOING);
 		tmp->next = outgoing;
 		outgoing = tmp;
 		/* If this line is up, don't try anybody else */
 		if (outgoing->chan->_state == AST_STATE_UP)
 			break;
 	}
-	
+
 	if (ast_strlen_zero(args.timeout)) {
 		to = -1;
 	} else {
@@ -1433,7 +1434,7 @@
 
 	time(&start_time);
 	peer = wait_for_answer(chan, outgoing, &to, peerflags, &pa, &num, ast_test_flag(&opts, OPT_PRIORITY_JUMP), &result);
-	
+
 	if (!peer) {
 		if (result) {
 			res = result;
@@ -1450,7 +1451,7 @@
 
 		strcpy(pa.status, "ANSWER");
 		/* Ah ha!  Someone answered within the desired timeframe.  Of course after this
-		   we will always return with -1 so that it is hung up properly after the 
+		   we will always return with -1 so that it is hung up properly after the
 		   conversation.  */
 		hanguptree(outgoing, peer);
 		outgoing = NULL;
@@ -1485,12 +1486,12 @@
 			if (!res)
 				res = ast_streamfile(peer, opt_args[OPT_ARG_ANNOUNCE], peer->language);
 			if (!res) {
-				digit = ast_waitstream(peer, AST_DIGIT_ANY); 
+				digit = ast_waitstream(peer, AST_DIGIT_ANY);
 			}
 			/* Ok, done. stop autoservice */
 			res = ast_autoservice_stop(chan);
 			if (digit > 0 && !res)
-				res = ast_senddigit(chan, digit); 
+				res = ast_senddigit(chan, digit);
 			else
 				res = digit;
 
@@ -1549,14 +1550,14 @@
 					res = -1;
 				} else if (!strcasecmp(macro_result, "CONGESTION") || !strcasecmp(macro_result, "CHANUNAVAIL")) {
 					ast_copy_string(pa.status, macro_result, sizeof(pa.status));
-					ast_set_flag(peerflags, OPT_GO_ON);	
+					ast_set_flag(peerflags, OPT_GO_ON);
 					res = -1;
 				} else if (!strcasecmp(macro_result, "CONTINUE")) {
-					/* hangup peer and keep chan alive assuming the macro has changed 
-					   the context / exten / priority or perhaps 
+					/* hangup peer and keep chan alive assuming the macro has changed
+					   the context / exten / priority or perhaps
 					   the next priority in the current exten is desired.
 					*/
-					ast_set_flag(peerflags, OPT_GO_ON);	
+					ast_set_flag(peerflags, OPT_GO_ON);
 					res = -1;
 				} else if (!strcasecmp(macro_result, "ABORT")) {
 					/* Hangup both ends unless the caller has the g flag */
@@ -1577,7 +1578,7 @@
 			if (calldurationlimit > 0) {
 				chan->whentohangup = time(NULL) + calldurationlimit;
 			}
-			if (!ast_strlen_zero(dtmfcalled)) { 
+			if (!ast_strlen_zero(dtmfcalled)) {
 				if (option_verbose > 2)
 					ast_verbose(VERBOSE_PREFIX_3 "Sending DTMF '%s' to the called party.\n", dtmfcalled);
 				res = ast_dtmf_stream(peer,chan,dtmfcalled,250);
@@ -1588,7 +1589,7 @@
 				res = ast_dtmf_stream(chan,peer,dtmfcalling,250);
 			}
 		}
-		
+
 		if (res) {	/* some error */
 			res = -1;
 			end_time = time(NULL);
@@ -1603,7 +1604,7 @@
 				ast_set_flag(&(config.features_caller), AST_FEATURE_DISCONNECT);
 			if (ast_test_flag(peerflags, OPT_CALLEE_MONITOR))
 				ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMON);
-			if (ast_test_flag(peerflags, OPT_CALLER_MONITOR)) 
+			if (ast_test_flag(peerflags, OPT_CALLER_MONITOR))
 				ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMON);
 			if (ast_test_flag(peerflags, OPT_CALLEE_PARK))
 				ast_set_flag(&(config.features_callee), AST_FEATURE_PARKCALL);
@@ -1651,7 +1652,7 @@
 				chan->hangupcause = peer->hangupcause;
 			ast_hangup(peer);
 		}
-	}	
+	}
 out:
 	if (moh) {
 		moh = 0;
@@ -1666,7 +1667,7 @@
 	senddialendevent(chan, pa.status);
 	if (option_debug)
 		ast_log(LOG_DEBUG, "Exiting with DIALSTATUS=%s.\n", pa.status);
-	
+
 	if ((ast_test_flag(peerflags, OPT_GO_ON)) && (!chan->_softhangup) && (res != AST_PBX_KEEPALIVE))
 		res = 0;
 
@@ -1689,11 +1690,11 @@
 	int sleep = 0, loops = 0, res = -1;
 	struct ast_module_user *u;
 	struct ast_flags peerflags;
-	
+
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "RetryDial requires an argument!\n");
 		return -1;
-	}	
+	}
 
 	u = ast_module_user_add(chan);
 
@@ -1717,20 +1718,20 @@
 			}
 		}
 	}
-	
+
 	if ((dialdata = strchr(dialdata, '|'))) {
 		*dialdata++ = '\0';
 	} else {
 		ast_log(LOG_ERROR, "%s requires more arguments\n",rapp);
 		goto done;
 	}
-		
+
 	if (sleep < 1000)
 		sleep = 10000;
 
 	if (!loops)
 		loops = -1;	/* run forever */
-	
+
 	context = pbx_builtin_getvar_helper(chan, "EXITCONTEXT");
 
 	res = 0;
@@ -1754,7 +1755,7 @@
 				if (sleep) {
 					if (!ast_test_flag(chan, AST_FLAG_MOH))
 						ast_moh_start(chan, NULL, NULL);
-					if (!res) 
+					if (!res)
 						res = ast_waitfordigit(chan, sleep);
 				}
 			}
@@ -1772,7 +1773,7 @@
 	}
 	if (loops == 0)
 		res = 0;
-	
+
 	if (ast_test_flag(chan, AST_FLAG_MOH))
 		ast_moh_stop(chan);
 done:
@@ -1788,7 +1789,7 @@
 	res |= ast_unregister_application(rapp);
 
 	ast_module_user_hangup_all();
-	
+
 	return res;
 }
 
@@ -1798,7 +1799,7 @@
 
 	res = ast_register_application(app, dial_exec, synopsis, descrip);
 	res |= ast_register_application(rapp, retrydial_exec, rsynopsis, rdescrip);
-	
+
 	return res;
 }
 

Modified: team/anthonyl/8350-codec/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/anthonyl/8350-codec/channels/chan_sip.c?view=diff&rev=47757&r1=47756&r2=47757
==============================================================================
--- team/anthonyl/8350-codec/channels/chan_sip.c (original)
+++ team/anthonyl/8350-codec/channels/chan_sip.c Thu Nov 16 14:09:04 2006
@@ -56,7 +56,7 @@
  * Incoming packets are received in the monitoring thread, then handled by
  * sipsock_read(). This function parses the packet and matches an existing
  * dialog or starts a new SIP dialog.
- * 
+ *
  * sipsock_read sends the packet to handle_request(), that parses a bit more.
  * if it's a response to an outbound request, it's sent to handle_response().
  * If it is a request, handle_request sends it to one of a list of functions
@@ -71,12 +71,12 @@
  * the sip_answer() function is called.
  *
  * The actual media - Video or Audio - is mostly handled by the RTP subsystem
- * in rtp.c 
- * 
+ * in rtp.c
+ *
  * \par Outbound calls
  * Outbound calls are set up by the PBX through the sip_request_call()
  * function. After that, they are activated by sip_call().
- * 
+ *
  * \par Hanging up
  * The PBX issues a hangup on both incoming and outgoing calls through
  * the sip_hangup() function
@@ -168,13 +168,13 @@
 /* guard limit must be larger than guard secs */
 /* guard min must be < 1000, and should be >= 250 */
 #define EXPIRY_GUARD_SECS       15                /*!< How long before expiry do we reregister */
-#define EXPIRY_GUARD_LIMIT      30                /*!< Below here, we use EXPIRY_GUARD_PCT instead of 
+#define EXPIRY_GUARD_LIMIT      30                /*!< Below here, we use EXPIRY_GUARD_PCT instead of
                                                    EXPIRY_GUARD_SECS */
-#define EXPIRY_GUARD_MIN        500                /*!< This is the minimum guard time applied. If 
-                                                   GUARD_PCT turns out to be lower than this, it 
+#define EXPIRY_GUARD_MIN        500                /*!< This is the minimum guard time applied. If
+                                                   GUARD_PCT turns out to be lower than this, it
                                                    will use this time instead.
                                                    This is in milliseconds. */
-#define EXPIRY_GUARD_PCT        0.20                /*!< Percentage of expires timeout to use when 
+#define EXPIRY_GUARD_PCT        0.20                /*!< Percentage of expires timeout to use when
                                                     below EXPIRY_GUARD_LIMIT */
 #define DEFAULT_EXPIRY 900                          /*!< Expire slowly */
 
@@ -196,7 +196,7 @@
 #define DEFAULT_RETRANS              1000             /*!< How frequently to retransmit Default: 2 * 500 ms in RFC 3261 */
 #define MAX_RETRANS                  6                /*!< Try only 6 times for retransmissions, a total of 7 transmissions */
 #define SIP_TIMER_T1		     500              /* SIP timer T1 (according to RFC 3261) */
-#define SIP_TRANS_TIMEOUT            32000            /*!< SIP request timeout (rfc 3261) 64*T1 
+#define SIP_TRANS_TIMEOUT            32000            /*!< SIP request timeout (rfc 3261) 64*T1
                                                       \todo Use known T1 for timeout (peerpoke)
                                                       */
 #define DEFAULT_TRANS_TIMEOUT        -1               /* Use default SIP transaction timeout */
@@ -224,7 +224,7 @@
 #define RTP 	1
 #define NO_RTP	0
 
-/*! \brief Authorization scheme for call transfers 
+/*! \brief Authorization scheme for call transfers
 \note Not a bitfield flag, since there are plans for other modes,
 	like "only allow transfers for authenticated devices" */
 enum transfermodes {
@@ -259,7 +259,7 @@
 	PARSE_REGISTER_QUERY,
 };
 
-enum subscriptiontype { 
+enum subscriptiontype {
 	NONE = 0,
 	XPIDF_XML,
 	DIALOG_INFO_XML,
@@ -304,7 +304,7 @@
 	SIP_PING,		/* Not supported at all, no standard but still implemented out there */
 };
 
-/*! \brief Authentication types - proxy or www authentication 
+/*! \brief Authentication types - proxy or www authentication
 	\note Endpoints, like Asterisk, should always use WWW authentication to
 	allow multiple authentications in the same call - to the proxy and
 	to the end point.
@@ -347,7 +347,7 @@
 };
 
 /*! XXX Note that sip_methods[i].id == i must hold or the code breaks */
-static const struct  cfsip_methods { 
+static const struct  cfsip_methods {
 	enum sipmethod id;
 	int need_rtp;		/*!< when this is the 'primary' use for a pvt structure, does it need RTP? */
 	char * const text;
@@ -372,10 +372,10 @@
 	{ SIP_PING,	 NO_RTP, "PING", 	CAN_CREATE_DIALOG_UNSUPPORTED_METHOD }
 };
 
-/*!  Define SIP option tags, used in Require: and Supported: headers 
- 	We need to be aware of these properties in the phones to use 
+/*!  Define SIP option tags, used in Require: and Supported: headers
+ 	We need to be aware of these properties in the phones to use
 	the replace: header. We should not do that without knowing
-	that the other end supports it... 
+	that the other end supports it...
 	This is nothing we can configure, we learn by the dialog
 	Supported: header on the REGISTER (peer) or the INVITE
 	(other devices)
@@ -411,11 +411,11 @@
 	char * const text;	/*!< Text id, as in standard */
 } sip_options[] = {	/* XXX used in 3 places */
 	/* RFC3891: Replaces: header for transfer */
-	{ SIP_OPT_REPLACES,	SUPPORTED,	"replaces" },	
+	{ SIP_OPT_REPLACES,	SUPPORTED,	"replaces" },
 	/* One version of Polycom firmware has the wrong label */
-	{ SIP_OPT_REPLACES,	SUPPORTED,	"replace" },	
+	{ SIP_OPT_REPLACES,	SUPPORTED,	"replace" },
 	/* RFC3262: PRACK 100% reliability */
-	{ SIP_OPT_100REL,	NOT_SUPPORTED,	"100rel" },	
+	{ SIP_OPT_100REL,	NOT_SUPPORTED,	"100rel" },
 	/* RFC4028: SIP Session Timers */
 	{ SIP_OPT_TIMER,	NOT_SUPPORTED,	"timer" },
 	/* RFC3959: SIP Early session support */
@@ -453,7 +453,7 @@
 #define ALLOWED_METHODS "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY"
 
 /*! \brief SIP Extensions we support */
-#define SUPPORTED_EXTENSIONS "replaces" 
+#define SUPPORTED_EXTENSIONS "replaces"
 
 /*! \brief Standard SIP port from RFC 3261. DO NOT CHANGE THIS */
 #define STANDARD_SIP_PORT	5060
@@ -467,7 +467,7 @@
 /* Default values, set and reset in reload_config before reading configuration */
 /* These are default values in the source. There are other recommended values in the
    sip.conf.sample for new installations. These may differ to keep backwards compatibility,
-   yet encouraging new behaviour on new installations 
+   yet encouraging new behaviour on new installations
  */
 #define DEFAULT_CONTEXT		"default"
 #define DEFAULT_MOHINTERPRET    "default"
@@ -506,7 +506,7 @@
 static int default_qualify;		/*!< Default Qualify= setting */
 static char default_vmexten[AST_MAX_EXTENSION];
 static char default_mohinterpret[MAX_MUSICCLASS];  /*!< Global setting for moh class to use when put on hold */
-static char default_mohsuggest[MAX_MUSICCLASS];	   /*!< Global setting for moh class to suggest when putting 
+static char default_mohsuggest[MAX_MUSICCLASS];	   /*!< Global setting for moh class to suggest when putting
                                                     *   a bridged channel on hold */
 static int default_maxcallbitrate;	/*!< Maximum bitrate for call */
 static struct ast_codec_pref default_prefs;		/*!< Default codec prefs */
@@ -524,10 +524,10 @@
 static int global_rtptimeout;		/*!< Time out call if no RTP */
 static int global_rtpholdtimeout;
 static int global_rtpkeepalive;		/*!< Send RTP keepalives */
-static int global_reg_timeout;	
+static int global_reg_timeout;
 static int global_regattempts_max;	/*!< Registration attempts before giving up */
 static int global_allowguest;		/*!< allow unauthenticated users/peers to connect? */
-static int global_allowsubscribe;	/*!< Flag for disabling ALL subscriptions, this is FALSE only if all peers are FALSE 
+static int global_allowsubscribe;	/*!< Flag for disabling ALL subscriptions, this is FALSE only if all peers are FALSE
 					    the global setting is in globals_flags[1] */
 static int global_mwitime;		/*!< Time between MWI checks for peers */
 static unsigned int global_tos_sip;		/*!< IP type of service for SIP packets */
@@ -653,7 +653,7 @@
 	SIP_DOMAIN_CONFIG,		/*!< This domain is from configuration */
 };
 
-/*! \brief Domain data structure. 
+/*! \brief Domain data structure.
 	\note In the future, we will connect this to a configuration tree specific
 	for this domain
 */
@@ -927,7 +927,7 @@
 	int prefcodec;				/*!< Preferred codec (outbound only) */
 	int noncodeccapability;			/*!< DTMF RFC2833 telephony-event */
 	int redircodecs;			/*!< Redirect codecs */
-	int maxcallbitrate;			/*!< Maximum Call Bitrate for Video Calls */	
+	int maxcallbitrate;			/*!< Maximum Call Bitrate for Video Calls */
 	struct t38properties t38;		/*!< T38 settings */
 	struct sockaddr_in udptlredirip;	/*!< Where our T.38 UDPTL should be going if not to us */
 	struct ast_udptl *udptl;		/*!< T.38 UDPTL session */
@@ -960,7 +960,7 @@
 							within this dialog.
 							NOT the request that opened the dialog
 						*/
-	
+
 	int initid;				/*!< Auto-congest ID if appropriate (scheduler) */
 	int autokillid;				/*!< Auto-kill ID (scheduler) */
 	enum transfermodes allowtransfer;	/*!< REFER: restriction scheme */
@@ -969,10 +969,10 @@
 	int stateid;				/*!< SUBSCRIBE: ID for devicestate subscriptions */
 	int laststate;				/*!< SUBSCRIBE: Last known extension state */
 	int dialogver;				/*!< SUBSCRIBE: Version for subscription dialog-info */
-	
+
 	struct ast_dsp *vad;			/*!< Inband DTMF Detection dsp */
-	
-	struct sip_peer *relatedpeer;		/*!< If this dialog is related to a peer, which one 
+
+	struct sip_peer *relatedpeer;		/*!< If this dialog is related to a peer, which one
 							Used in peerpoke, mwi subscriptions */
 	struct sip_registry *registry;		/*!< If this is a REGISTER dialog, to which registry */
 	struct ast_rtp *rtp;			/*!< RTP Session */
@@ -1020,7 +1020,7 @@
 	int timer_t1;				/*!< SIP Timer T1, estimated RTT or 500 ms */
 	int packetlen;				/*!< Length of packet */
 	char data[0];
-};	
+};
 
 /*! \brief Structure for SIP user data. User's place calls to us */
 struct sip_user {
@@ -1064,7 +1064,7 @@
 	struct sip_auth *auth;		/*!< Realm authentication list */
 	char context[AST_MAX_CONTEXT];	/*!< Default context for incoming calls */
 	char subscribecontext[AST_MAX_CONTEXT];	/*!< Default context for subscriptions */
-	char username[80];		/*!< Temporary username until registration */ 
+	char username[80];		/*!< Temporary username until registration */
 	char accountcode[AST_MAX_ACCOUNT_CODE];	/*!< Account code */
 	int amaflags;			/*!< AMA Flags (for billing) */
 	char tohost[MAXHOSTNAMELEN];	/*!< If not dynamic, IP address */
@@ -1101,7 +1101,7 @@
 	struct ast_dnsmgr_entry *dnsmgr;/*!<  DNS refresh manager for peer */
 	struct sockaddr_in addr;	/*!<  IP address of peer */
 	int maxcallbitrate;		/*!< Maximum Bitrate for a video call */
-	
+
 	/* Qualification */
 	struct sip_pvt *call;		/*!<  Call pointer */
 	int pokeexpire;			/*!<  When to expire poke (qualify= checking) */
@@ -1131,7 +1131,7 @@
 		AST_STRING_FIELD(username);	/*!< Who we are registering as */
 		AST_STRING_FIELD(authuser);	/*!< Who we *authenticate* as */
 		AST_STRING_FIELD(hostname);	/*!< Domain or host we register to */
-		AST_STRING_FIELD(secret);	/*!< Password in clear text */	
+		AST_STRING_FIELD(secret);	/*!< Password in clear text */
 		AST_STRING_FIELD(md5secret);	/*!< Password in md5 */
 		AST_STRING_FIELD(callback);	/*!< Contact extension */
 		AST_STRING_FIELD(random);
@@ -1391,7 +1391,7 @@
 static int sip_do_reload(enum channelreloadreason reason);
 static int sip_reload(int fd, int argc, char *argv[]);
 
-/*--- Debugging 
+/*--- Debugging
 	Functions for enabling debug per IP or fully, or enabling history logging for
 	a SIP dialog
 */
@@ -1557,7 +1557,7 @@
 };
 
 /**--- some list management macros. **/
- 
+
 #define UNLINK(element, head, prev) do {	\
 	if (prev)				\
 		(prev)->next = (element)->next;	\
@@ -1663,7 +1663,7 @@
 static int find_sip_method(const char *msg)
 {
 	int i, res = 0;
-	
+
 	if (ast_strlen_zero(msg))
 		return 0;
 	for (i = 1; i < (sizeof(sip_methods) / sizeof(sip_methods[0])) && !res; i++) {
@@ -1718,7 +1718,7 @@
 }
 
 /*! \brief See if we pass debug IP filter */
-static inline int sip_debug_test_addr(const struct sockaddr_in *addr) 
+static inline int sip_debug_test_addr(const struct sockaddr_in *addr)
 {
 	if (!sipdebug)
 		return 0;
@@ -1744,7 +1744,7 @@
 }
 
 /*! \brief Test PVT for debugging output */
-static inline int sip_debug_test_pvt(struct sip_pvt *p) 
+static inline int sip_debug_test_pvt(struct sip_pvt *p)
 {
 	if (!sipdebug)
 		return 0;
@@ -1805,7 +1805,7 @@
 		}
 		*us = externip.sin_addr;
 		if (option_debug) {
-			ast_log(LOG_DEBUG, "Target address %s is not local, substituting externip\n", 
+			ast_log(LOG_DEBUG, "Target address %s is not local, substituting externip\n",
 				ast_inet_ntoa(*(struct in_addr *)&them->s_addr));
 		}
 	} else if (bindaddr.sin_addr.s_addr)
@@ -1813,7 +1813,7 @@
 	return AST_SUCCESS;
 }
 
-/*! \brief Append to SIP dialog history 
+/*! \brief Append to SIP dialog history
 	\return Always returns 0 */
 #define append_history(p, event, fmt , args... )	append_history_full(p, "%-15s " fmt, event, ## args)
 
@@ -1877,17 +1877,17 @@
  				pkt->timer_a = 2 ;
  			else
  				pkt->timer_a = 2 * pkt->timer_a;
- 
+
  			/* For non-invites, a maximum of 4 secs */
  			siptimer_a = pkt->timer_t1 * pkt->timer_a;	/* Double each time */
  			if (pkt->method != SIP_INVITE && siptimer_a > 4000)
  				siptimer_a = 4000;
- 		
+
  			/* Reschedule re-transmit */
 			reschedule = siptimer_a;
  			if (option_debug > 3)
  				ast_log(LOG_DEBUG, "** SIP timers: Rescheduling retransmission %d to %d ms (t1 %d ms (Retrans id #%d)) \n", pkt->retrans +1, siptimer_a, pkt->timer_t1, pkt->retransid);
- 		} 
+ 		}
 
 		if (sip_debug_test_pvt(pkt->owner)) {
 			const struct sockaddr_in *dst = sip_real_dst(pkt->owner);
@@ -1901,7 +1901,7 @@
 		__sip_xmit(pkt->owner, pkt->data, pkt->packetlen);
 		sip_pvt_unlock(pkt->owner);
 		return  reschedule;
-	} 
+	}
 	/* Too many retries */
 	if (pkt->owner && pkt->method != SIP_OPTIONS) {
 		if (ast_test_flag(pkt, FLAG_FATAL) || sipdebug)	/* Tell us if it's critical or if we're debugging */
@@ -1911,7 +1911,7 @@
 			ast_log(LOG_WARNING, "Cancelling retransmit of OPTIONs (call id %s) \n", pkt->owner->callid);
 	}
 	append_history(pkt->owner, "MaxRetries", "%s", (ast_test_flag(pkt, FLAG_FATAL)) ? "(Critical)" : "(Non-critical)");
- 		
+
 	pkt->retransid = -1;
 
 	if (ast_test_flag(pkt, FLAG_FATAL)) {
@@ -1930,7 +1930,7 @@
 
 			/* Let the peerpoke system expire packets when the timer expires for poke_noanswer */
 			if (pkt->method != SIP_OPTIONS)
-				ast_set_flag(&pkt->owner->flags[0], SIP_NEEDDESTROY);	
+				ast_set_flag(&pkt->owner->flags[0], SIP_NEEDDESTROY);
 		}
 	}
 	/* Remove the packet */
@@ -1948,8 +1948,8 @@
 	return 0;
 }
 
-/*! \brief Transmit packet with retransmits 
-	\return 0 on success, -1 on failure to allocate packet 
+/*! \brief Transmit packet with retransmits
+	\return 0 on success, -1 on failure to allocate packet
 */
 static enum sip_result __sip_reliable_xmit(struct sip_pvt *p, int seqno, int resp, char *data, int len, int fatal, int sipmethod)
 {
@@ -2169,7 +2169,7 @@
 	if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) {
 		struct sip_request tmp;
 		parse_copy(&tmp, req);
-		append_history(p, reliable ? "TxRespRel" : "TxResp", "%s / %s - %s", tmp.data, get_header(&tmp, "CSeq"), 
+		append_history(p, reliable ? "TxRespRel" : "TxResp", "%s / %s - %s", tmp.data, get_header(&tmp, "CSeq"),
 			(tmp.method == SIP_RESPONSE || tmp.method == SIP_UNKNOWN) ? tmp.rlPart2 : sip_methods[tmp.method].text);
 	}
 	res = (reliable) ?
@@ -2349,10 +2349,10 @@
 	if (debug)
 		ast_verbose("Really sending text %s on %s\n", text, ast->name);
 	transmit_message_with_text(p, text);
-	return 0;	
-}
-
-/*! \brief Update peer object in realtime storage 
+	return 0;
+}
+
+/*! \brief Update peer object in realtime storage
 	If the Asterisk system name is set in asterisk.conf, we will use
 	that name and store that in the "regserver" field in the sippeers
 	table to facilitate multi-server setups.
@@ -2368,11 +2368,11 @@
 
 	time_t nowtime = time(NULL) + expirey;
 	const char *fc = fullcontact ? "fullcontact" : NULL;
-	
+
 	snprintf(regseconds, sizeof(regseconds), "%d", (int)nowtime);	/* Expiration time */
 	ast_copy_string(ipaddr, ast_inet_ntoa(sin->sin_addr), sizeof(ipaddr));
 	snprintf(port, sizeof(port), "%d", ntohs(sin->sin_port));
-	
+
 	if (ast_strlen_zero(sysname))	/* No system name, disable this */
 		sysname = NULL;
 	else if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTSAVE_SYSNAME))
@@ -2471,7 +2471,7 @@
 
 
 /*! \brief  realtime_peer: Get peer from realtime storage
- * Checks the "sippeers" realtime family from extconfig.conf 
+ * Checks the "sippeers" realtime family from extconfig.conf
  * \todo Consider adding check of port address when matching here to follow the same
  * 	algorithm as for static peers. Will we break anything by adding that?
 */
@@ -2483,7 +2483,7 @@
 	char ipaddr[INET_ADDRSTRLEN];
 
 	/* First check on peer name */
-	if (newpeername) 
+	if (newpeername)
 		var = ast_load_realtime("sippeers", "name", newpeername, NULL);
 	else if (sin) {	/* Then check on IP address for dynamic peers */
 		ast_copy_string(ipaddr, ast_inet_ntoa(sin->sin_addr), sizeof(ipaddr));
@@ -2505,7 +2505,7 @@
 			newpeername = tmp->value;
 		}
 	}
-	
+
 	if (!newpeername) {	/* Did not find peer in realtime */
 		ast_log(LOG_WARNING, "Cannot Determine peer name ip=%s\n", ipaddr);
 		ast_variables_destroy(var);
@@ -2546,12 +2546,12 @@
 {
 	/* We know name is the first field, so we can cast */
 	struct sip_peer *p = (struct sip_peer *) name;
-	return 	!(!inaddrcmp(&p->addr, sin) || 
+	return 	!(!inaddrcmp(&p->addr, sin) ||
 					(ast_test_flag(&p->flags[0], SIP_INSECURE_PORT) &&
 					(p->addr.sin_addr.s_addr == sin->sin_addr.s_addr)));
 }
 
-/*! \brief Locate peer by name or ip address 
+/*! \brief Locate peer by name or ip address
  *	This is used on incoming SIP message to find matching peer on ip
 	or outgoing message to find matching peer on name */
 static struct sip_peer *find_peer(const char *peer, struct sockaddr_in *sin, int realtime)
@@ -2609,7 +2609,7 @@
 	}
 
 	user = build_user(username, var, !ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS));
-	
+
 	if (!user) {	/* No user found */
 		ast_variables_destroy(var);
 		return NULL;
@@ -2629,9 +2629,9 @@
 	return user;
 }
 
-/*! \brief Locate user by name 
+/*! \brief Locate user by name
  * Locates user by name (From: sip uri user name part) first
- * from in-memory list (static configuration) then from 
+ * from in-memory list (static configuration) then from
  * realtime storage (defined in extconfig.conf) */
 static struct sip_user *find_user(const char *name, int realtime)
 {
@@ -2672,7 +2672,7 @@
 	    (!peer->maxms || ((peer->lastms >= 0)  && (peer->lastms <= peer->maxms)))) {
 		dialog->sa = (peer->addr.sin_addr.s_addr) ? peer->addr : peer->defaddr;
 		dialog->recv = dialog->sa;
-	} else 
+	} else
 		return -1;
 
 	ast_copy_flags(&dialog->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY);
@@ -2759,12 +2759,12 @@
 	if (peer->call_limit)
 		ast_set_flag(&dialog->flags[0], SIP_CALL_LIMIT);
 	dialog->maxcallbitrate = peer->maxcallbitrate;
-	
+
 	return 0;
 }
 
 /*! \brief create address structure from peer name
- *      Or, if peer not found, find it in the global DNS 
+ *      Or, if peer not found, find it in the global DNS
  *      returns TRUE (-1) on failure, FALSE on success */
 static int create_addr(struct sip_pvt *dialog, const char *opeer)
 {
@@ -2836,7 +2836,7 @@
 }
 
 
-/*! \brief Initiate SIP call from PBX 
+/*! \brief Initiate SIP call from PBX
  *      used from the dial() application      */
 static int sip_call(struct ast_channel *ast, char *dest, int timeout)
 {
@@ -2844,7 +2844,7 @@
 	struct sip_pvt *p;
 	struct varshead *headp;
 	struct ast_var_t *current;

[... 4251 lines stripped ...]


More information about the svn-commits mailing list