Merged revisions 65679-65680 via svnmerge from
authorKevin P. Fleming <kpfleming@digium.com>
Wed, 23 May 2007 20:39:42 +0000 (20:39 +0000)
committerKevin P. Fleming <kpfleming@digium.com>
Wed, 23 May 2007 20:39:42 +0000 (20:39 +0000)
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r65679 | kpfleming | 2007-05-23 16:30:24 -0400 (Wed, 23 May 2007) | 2 lines

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)

........
r65680 | kpfleming | 2007-05-23 16:35:50 -0400 (Wed, 23 May 2007) | 2 lines

clear the 'delay PBX' flag when we are ready to start the PBX

........

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@65681 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_iax2.c

index 5cbe6fd..3bbae35 100644 (file)
@@ -285,6 +285,9 @@ enum iax2_flags {
        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*/
 };
 
 static int global_rtautoclear = 120;
@@ -3423,7 +3426,7 @@ static int iax2_getpeertrunk(struct sockaddr_in sin)
 }
 
 /*! \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;
@@ -3479,7 +3482,9 @@ static struct ast_channel *ast_iax2_new(int callno, int state, int capability)
        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);
@@ -6984,6 +6989,17 @@ retryowner:
                                        ast_log(LOG_DEBUG, "For call=%d, set last=%d\n", fr->callno, fr->ts);
                        }
 
+                       if (ast_test_flag(iaxs[fr->callno], IAX_DELAYPBXSTART)) {
+                               ast_clear_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 */
@@ -7194,7 +7210,7 @@ retryowner:
                                                                                                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 if (ies.vars) {
                                                                        struct ast_variable *var, *prev = NULL;
@@ -7593,7 +7609,7 @@ retryowner2:
                                                                                        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);
@@ -7621,7 +7637,7 @@ retryowner2:
                                                        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);
                                        }
                                }
@@ -8317,7 +8333,7 @@ static struct ast_channel *iax2_request(const char *type, int format, void *data
        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]);