[asterisk-commits] kpfleming: branch 1.4 r65679 - /branches/1.4/channels/chan_iax2.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed May 23 13:30:25 MST 2007


Author: kpfleming
Date: Wed May 23 15:30:24 2007
New Revision: 65679

URL: http://svn.digium.com/view/asterisk?view=rev&rev=65679
Log:
don't start a PBX on a new incoming IAX2 channel until we have some sort of response to our ACCEPT (ACK or anything else)

Modified:
    branches/1.4/channels/chan_iax2.c

Modified: branches/1.4/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_iax2.c?view=diff&rev=65679&r1=65678&r2=65679
==============================================================================
--- branches/1.4/channels/chan_iax2.c (original)
+++ branches/1.4/channels/chan_iax2.c Wed May 23 15:30:24 2007
@@ -268,6 +268,9 @@
 	IAX_TRUNKTIMESTAMPS =	(1 << 22),	/*!< Send trunk timestamps */
 	IAX_TRANSFERMEDIA = 	(1 << 23),      /*!< When doing IAX2 transfers, transfer media only */
 	IAX_MAXAUTHREQ =        (1 << 24),      /*!< Maximum outstanding AUTHREQ restriction is in place */
+	IAX_DELAYPBXSTART =	(1 << 25),	/*!< Don't start a PBX on the channel until the peer sends us a
+						     response, so that we've achieved a three-way handshake with
+						     them before sending voice or anything else*/
 } iax2_flags;
 
 static int global_rtautoclear = 120;
@@ -3258,7 +3261,7 @@
 }
 
 /*! \brief  Create new call, interface with the PBX core */
-static struct ast_channel *ast_iax2_new(int callno, int state, int capability)
+static struct ast_channel *ast_iax2_new(int callno, int state, int capability, unsigned int delaypbx)
 {
 	struct ast_channel *tmp;
 	struct chan_iax2_pvt *i;
@@ -3313,7 +3316,9 @@
 	for (v = i->vars ; v ; v = v->next)
 		pbx_builtin_setvar_helper(tmp, v->name, v->value);
 
-	if (state != AST_STATE_DOWN) {
+	if (delaypbx) {
+		ast_set_flag(i, IAX_DELAYPBXSTART);
+	} else if (state != AST_STATE_DOWN) {
 		if (ast_pbx_start(tmp)) {
 			ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
 			ast_hangup(tmp);
@@ -6708,6 +6713,16 @@
 					ast_log(LOG_DEBUG, "For call=%d, set last=%d\n", fr->callno, fr->ts);
 			}
 
+			if (ast_test_flag(iaxs[fr->callno], IAX_DELAYPBXSTART)) {
+				if (ast_pbx_start(iaxs[fr->callno]->owner)) {
+					ast_log(LOG_WARNING, "Unable to start PBX on %s\n", iaxs[fr->callno]->owner->name);
+					ast_hangup(iaxs[fr->callno]->owner);
+					iaxs[fr->callno]->owner = NULL;
+					ast_mutex_unlock(&iaxsl[fr->callno]);
+					return 1;
+				}
+			}
+
 			switch(f.subclass) {
 			case IAX_COMMAND_ACK:
 				/* Do nothing */
@@ -6916,7 +6931,7 @@
 												VERBOSE_PREFIX_4,
 												using_prefs);
 								
-								if(!(c = ast_iax2_new(fr->callno, AST_STATE_RING, format)))
+								if(!(c = ast_iax2_new(fr->callno, AST_STATE_RING, format, 1)))
 									iax2_destroy(fr->callno);
 							} else {
 								ast_set_flag(&iaxs[fr->callno]->state, IAX_STATE_TBD);
@@ -7298,7 +7313,7 @@
 											using_prefs);
 
 							ast_set_flag(&iaxs[fr->callno]->state, IAX_STATE_STARTED);
-							if(!(c = ast_iax2_new(fr->callno, AST_STATE_RING, format)))
+							if(!(c = ast_iax2_new(fr->callno, AST_STATE_RING, format, 0)))
 								iax2_destroy(fr->callno);
 						} else {
 							ast_set_flag(&iaxs[fr->callno]->state, IAX_STATE_TBD);
@@ -7326,7 +7341,7 @@
 							ast_verbose(VERBOSE_PREFIX_3 "Accepting DIAL from %s, formats = 0x%x\n", ast_inet_ntoa(sin.sin_addr), iaxs[fr->callno]->peerformat);
 						ast_set_flag(&iaxs[fr->callno]->state, IAX_STATE_STARTED);
 						send_command(iaxs[fr->callno], AST_FRAME_CONTROL, AST_CONTROL_PROGRESS, 0, NULL, 0, -1);
-						if(!(c = ast_iax2_new(fr->callno, AST_STATE_RING, iaxs[fr->callno]->peerformat)))
+						if(!(c = ast_iax2_new(fr->callno, AST_STATE_RING, iaxs[fr->callno]->peerformat, 0)))
 							iax2_destroy(fr->callno);
 					}
 				}
@@ -8015,7 +8030,7 @@
 	if (cai.found)
 		ast_string_field_set(iaxs[callno], host, pds.peer);
 
-	c = ast_iax2_new(callno, AST_STATE_DOWN, cai.capability);
+	c = ast_iax2_new(callno, AST_STATE_DOWN, cai.capability, 0);
 
 	ast_mutex_unlock(&iaxsl[callno]);
 



More information about the asterisk-commits mailing list