Merged revisions 76803 via svnmerge from
authorTilghman Lesher <tilghman@meg.abyt.es>
Tue, 24 Jul 2007 17:05:10 +0000 (17:05 +0000)
committerTilghman Lesher <tilghman@meg.abyt.es>
Tue, 24 Jul 2007 17:05:10 +0000 (17:05 +0000)
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r76803 | qwell | 2007-07-24 11:32:20 -0500 (Tue, 24 Jul 2007) | 3 lines

Don't create the Asterisk channel until we are starting the PBX on it.
(ASA-2007-018)

........

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

channels/chan_iax2.c

index 33d3b81..b551359 100644 (file)
@@ -519,6 +519,10 @@ struct chan_iax2_pvt {
        unsigned short callno;
        /*! Peer callno */
        unsigned short peercallno;
+       /*! Negotiated format, this is only used to remember what format was
+           chosen for an unauthenticated call so that the channel can get
+           created later using the right format */
+       int chosenformat;
        /*! Peer selected format */
        int peerformat;
        /*! Peer capability */
@@ -2099,7 +2103,7 @@ static int iax2_prune_realtime(int fd, int argc, char *argv[])
        } else if ((peer = find_peer(argv[3], 0))) {
                if(ast_test_flag(peer, IAX_RTCACHEFRIENDS)) {
                        ast_set_flag(peer, IAX_RTAUTOCLEAR);
-                       expire_registry((void*)peer->name);
+                       expire_registry((void *)peer->name);
                        ast_cli(fd, "OK peer %s was removed from the cache.\n", argv[3]);
                } else {
                        ast_cli(fd, "SORRY peer %s is not eligible for this operation.\n", argv[3]);
@@ -3530,7 +3534,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, unsigned int delaypbx)
+static struct ast_channel *ast_iax2_new(int callno, int state, int capability)
 {
        struct ast_channel *tmp;
        struct chan_iax2_pvt *i;
@@ -3611,9 +3615,7 @@ static struct ast_channel *ast_iax2_new(int callno, int state, int capability, u
                }
        }
 
-       if (delaypbx) {
-               ast_set_flag(i, IAX_DELAYPBXSTART);
-       } else if (state != AST_STATE_DOWN) {
+       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);
@@ -7273,12 +7275,42 @@ static int socket_process(struct iax2_thread *thread)
                    (f.frametype == AST_FRAME_IAX)) {
                        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;
+                               if (!ast_iax2_new(fr->callno, AST_STATE_RING, iaxs[fr->callno]->chosenformat)) {
                                        ast_mutex_unlock(&iaxsl[fr->callno]);
                                        return 1;
+                               } else if (ies.vars) {
+                                       struct ast_datastore *variablestore;
+                                       struct ast_variable *var, *prev = NULL;
+                                       AST_LIST_HEAD(, ast_var_t) *varlist;
+                                       varlist = ast_calloc(1, sizeof(*varlist));
+                                       variablestore = ast_channel_datastore_alloc(&iax2_variable_datastore_info, NULL);
+                                       if (variablestore && varlist) {
+                                               variablestore->data = varlist;
+                                               variablestore->inheritance = DATASTORE_INHERIT_FOREVER;
+                                               AST_LIST_HEAD_INIT(varlist);
+                                               for (var = ies.vars; var; var = var->next) {
+                                                       struct ast_var_t *newvar = ast_var_assign(var->name, var->value);
+                                                       if (prev)
+                                                               ast_free(prev);
+                                                       prev = var;
+                                                       if (!newvar) {
+                                                               /* Don't abort list traversal, as this would leave ies.vars in an inconsistent state. */
+                                                               ast_log(LOG_ERROR, "Memory allocation error while processing IAX2 variables\n");
+                                                       } else {
+                                                               AST_LIST_INSERT_TAIL(varlist, newvar, entries);
+                                                       }
+                                               }
+                                               if (prev)
+                                                       free(prev);
+                                               ies.vars = NULL;
+                                               ast_channel_datastore_add(c, variablestore);
+                                       } else {
+                                               ast_log(LOG_ERROR, "Memory allocation error while processing IAX2 variables\n");
+                                               if (variablestore)
+                                                       ast_channel_datastore_free(variablestore);
+                                               if (varlist)
+                                                       ast_free(varlist);
+                                       }
                                }
                        }
                }
@@ -7565,44 +7597,8 @@ retryowner:
                                                                                                VERBOSE_PREFIX_4,
                                                                                                using_prefs);
                                                                
-                                                               /* create an Asterisk channel for this call, but don't start
-                                                                  a PBX on it until we have received a full frame from the peer */
-                                                               if (!(c = ast_iax2_new(fr->callno, AST_STATE_RING, format, 1)))
-                                                                       iax2_destroy(fr->callno);
-                                                               else if (ies.vars) {
-                                                                       struct ast_datastore *variablestore;
-                                                                       struct ast_variable *var, *prev = NULL;
-                                                                       AST_LIST_HEAD(, ast_var_t) *varlist;
-                                                                       varlist = ast_calloc(1, sizeof(*varlist));
-                                                                       variablestore = ast_channel_datastore_alloc(&iax2_variable_datastore_info, NULL);
-                                                                       if (variablestore && varlist) {
-                                                                               variablestore->data = varlist;
-                                                                               variablestore->inheritance = DATASTORE_INHERIT_FOREVER;
-                                                                               AST_LIST_HEAD_INIT(varlist);
-                                                                               for (var = ies.vars; var; var = var->next) {
-                                                                                       struct ast_var_t *newvar = ast_var_assign(var->name, var->value);
-                                                                                       if (prev)
-                                                                                               ast_free(prev);
-                                                                                       prev = var;
-                                                                                       if (!newvar) {
-                                                                                               /* Don't abort list traversal, as this would leave ies.vars in an inconsistent state. */
-                                                                                               ast_log(LOG_ERROR, "Memory allocation error while processing IAX2 variables\n");
-                                                                                       } else {
-                                                                                               AST_LIST_INSERT_TAIL(varlist, newvar, entries);
-                                                                                       }
-                                                                               }
-                                                                               if (prev)
-                                                                                       ast_free(prev);
-                                                                               ies.vars = NULL;
-                                                                               ast_channel_datastore_add(c, variablestore);
-                                                                       } else {
-                                                                               ast_log(LOG_ERROR, "Memory allocation error while processing IAX2 variables\n");
-                                                                               if (variablestore)
-                                                                                       ast_channel_datastore_free(variablestore);
-                                                                               if (varlist)
-                                                                                       ast_free(varlist);
-                                                                       }
-                                                               }
+                                                               iaxs[fr->callno]->chosenformat = format;
+                                                               ast_set_flag(iaxs[fr->callno], IAX_DELAYPBXSTART);
                                                        } else {
                                                                ast_set_flag(&iaxs[fr->callno]->state, IAX_STATE_TBD);
                                                                /* If this is a TBD call, we're ready but now what...  */
@@ -7981,7 +7977,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, 0)))
+                                                       if (!(c = ast_iax2_new(fr->callno, AST_STATE_RING, format)))
                                                                iax2_destroy(fr->callno);
                                                        else if (ies.vars) {
                                                                struct ast_datastore *variablestore;
@@ -8043,8 +8039,42 @@ 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, 0)))
+                                               if (!(c = ast_iax2_new(fr->callno, AST_STATE_RING, iaxs[fr->callno]->peerformat)))
                                                        iax2_destroy(fr->callno);
+                                               else if (ies.vars) {
+                                                       struct ast_datastore *variablestore;
+                                                       struct ast_variable *var, *prev = NULL;
+                                                       AST_LIST_HEAD(, ast_var_t) *varlist;
+                                                       varlist = ast_calloc(1, sizeof(*varlist));
+                                                       variablestore = ast_channel_datastore_alloc(&iax2_variable_datastore_info, NULL);
+                                                       if (variablestore && varlist) {
+                                                               variablestore->data = varlist;
+                                                               variablestore->inheritance = DATASTORE_INHERIT_FOREVER;
+                                                               AST_LIST_HEAD_INIT(varlist);
+                                                               for (var = ies.vars; var; var = var->next) {
+                                                                       struct ast_var_t *newvar = ast_var_assign(var->name, var->value);
+                                                                       if (prev)
+                                                                               ast_free(prev);
+                                                                       prev = var;
+                                                                       if (!newvar) {
+                                                                               /* Don't abort list traversal, as this would leave ies.vars in an inconsistent state. */
+                                                                               ast_log(LOG_ERROR, "Memory allocation error while processing IAX2 variables\n");
+                                                                       } else {
+                                                                               AST_LIST_INSERT_TAIL(varlist, newvar, entries);
+                                                                       }
+                                                               }
+                                                               if (prev)
+                                                                       ast_free(prev);
+                                                               ies.vars = NULL;
+                                                               ast_channel_datastore_add(c, variablestore);
+                                                       } else {
+                                                               ast_log(LOG_ERROR, "Memory allocation error while processing IAX2 variables\n");
+                                                               if (variablestore)
+                                                                       ast_channel_datastore_free(variablestore);
+                                                               if (varlist)
+                                                                       ast_free(varlist);
+                                                       }
+                                               }
                                        }
                                }
                                break;
@@ -8747,7 +8777,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, 0);
+       c = ast_iax2_new(callno, AST_STATE_DOWN, cai.capability);
 
        ast_mutex_unlock(&iaxsl[callno]);