This commits the performance mods that give the priority processing engine in the...
authorSteve Murphy <murf@digium.com>
Thu, 1 Nov 2007 22:26:51 +0000 (22:26 +0000)
committerSteve Murphy <murf@digium.com>
Thu, 1 Nov 2007 22:26:51 +0000 (22:26 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@88166 65c4cc65-6c06-0410-ace0-fbb531ad65f3

25 files changed:
apps/app_dial.c
apps/app_exec.c
apps/app_macro.c
apps/app_minivm.c
apps/app_mixmonitor.c
apps/app_playback.c
apps/app_queue.c
apps/app_rpt.c
cdr/cdr_custom.c
cdr/cdr_manager.c
cdr/cdr_sqlite3_custom.c
funcs/func_cut.c
funcs/func_logic.c
funcs/func_odbc.c
funcs/func_strings.c
include/asterisk/pbx.h
main/logger.c
main/pbx.c
pbx/pbx_config.c
pbx/pbx_dundi.c
pbx/pbx_loopback.c
pbx/pbx_realtime.c
res/ael/pval.c
res/res_agi.c
utils/extconf.c

index 3a1f123..ee7c41f 100644 (file)
@@ -1791,20 +1791,20 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
 
                if (ast_test_flag64(&opts, OPT_PEER_H) && ast_exists_extension(peer, peer->context, "h", 1, peer->cid.cid_num)) {
                        int autoloopflag;
+                       int found;
                        strcpy(peer->exten, "h");
                        peer->priority = 1;
                        autoloopflag = ast_test_flag(peer, AST_FLAG_IN_AUTOLOOP);       /* save value to restore at the end */
                        ast_set_flag(peer, AST_FLAG_IN_AUTOLOOP);
                        
-                       while (ast_exists_extension(peer, peer->context, peer->exten, peer->priority, peer->cid.cid_num)) {
-                               if ((res = ast_spawn_extension(peer, peer->context, peer->exten, peer->priority, peer->cid.cid_num))) {
-                                       /* Something bad happened, or a hangup has been requested. */
-                                       ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", peer->context, peer->exten, peer->priority, peer->name);
-                                       ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", peer->context, peer->exten, peer->priority, peer->name);
-                                       break;
-                               }
+                       while ((res = ast_spawn_extension(peer, peer->context, peer->exten, peer->priority, peer->cid.cid_num, &found,1))) {
                                peer->priority++;
                        }
+                       if (found && res) {
+                               /* Something bad happened, or a hangup has been requested. */
+                               ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", peer->context, peer->exten, peer->priority, peer->name);
+                               ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", peer->context, peer->exten, peer->priority, peer->name);
+                       }
                        ast_set2_flag(peer, autoloopflag, AST_FLAG_IN_AUTOLOOP);  /* set it back the way it was */
                }
                if (res != AST_PBX_NO_HANGUP_PEER) {
index 12b91a4..048c338 100644 (file)
@@ -92,7 +92,7 @@ static char *execif_descrip =
 static int exec_exec(struct ast_channel *chan, void *data)
 {
        int res = 0;
-       char *s, *appname, *endargs, args[MAXRESULT] = "";
+       char *s, *appname, *endargs, args[MAXRESULT];
        struct ast_app *app;
 
        if (ast_strlen_zero(data))
@@ -122,7 +122,7 @@ static int exec_exec(struct ast_channel *chan, void *data)
 static int tryexec_exec(struct ast_channel *chan, void *data)
 {
        int res = 0;
-       char *s, *appname, *endargs, args[MAXRESULT] = "";
+       char *s, *appname, *endargs, args[MAXRESULT];
        struct ast_app *app;
 
        if (ast_strlen_zero(data))
index 32e9d2d..07284ca 100644 (file)
@@ -271,6 +271,7 @@ static int _macro_exec(struct ast_channel *chan, void *data, int exclusive)
        while(ast_exists_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num)) {
                struct ast_context *c;
                struct ast_exten *e;
+               int foundx;
                runningapp[0] = '\0';
                runningdata[0] = '\0';
 
@@ -299,7 +300,7 @@ static int _macro_exec(struct ast_channel *chan, void *data, int exclusive)
                /* Reset the macro depth, if it was changed in the last iteration */
                pbx_builtin_setvar_helper(chan, "MACRO_DEPTH", depthc);
 
-               if ((res = ast_spawn_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num))) {
+               if ((res = ast_spawn_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num, &foundx,1))) {
                        /* Something bad happened, or a hangup has been requested. */
                        if (((res >= '0') && (res <= '9')) || ((res >= 'A') && (res <= 'F')) ||
                        (res == '*') || (res == '#')) {
@@ -330,7 +331,7 @@ static int _macro_exec(struct ast_channel *chan, void *data, int exclusive)
                        gosub_level++;
                        ast_debug(1, "Incrementing gosub_level\n");
                } else if (!strcasecmp(runningapp, "GOSUBIF")) {
-                       char tmp2[1024] = "", *cond, *app, *app2 = tmp2;
+                       char tmp2[1024], *cond, *app, *app2 = tmp2;
                        pbx_substitute_variables_helper(chan, runningdata, tmp2, sizeof(tmp2) - 1);
                        cond = strsep(&app2, "?");
                        app = strsep(&app2, ":");
@@ -353,7 +354,7 @@ static int _macro_exec(struct ast_channel *chan, void *data, int exclusive)
                        ast_debug(1, "Decrementing gosub_level\n");
                } else if (!strncasecmp(runningapp, "EXEC", 4)) {
                        /* Must evaluate args to find actual app */
-                       char tmp2[1024] = "", *tmp3 = NULL;
+                       char tmp2[1024], *tmp3 = NULL;
                        pbx_substitute_variables_helper(chan, runningdata, tmp2, sizeof(tmp2) - 1);
                        if (!strcasecmp(runningapp, "EXECIF")) {
                                tmp3 = strchr(tmp2, '|');
index bb352dc..50300a9 100644 (file)
@@ -1025,7 +1025,6 @@ static int sendmail(struct minivm_template *template, struct minivm_account *vmu
 
                ast_debug(4, "-_-_- Fromaddress template: %s\n", fromaddress);
                if ((passdata = alloca(vmlen))) {
-                       memset(passdata, 0, vmlen);
                        pbx_substitute_variables_helper(ast, fromaddress, passdata, vmlen);
                        len_passdata = strlen(passdata) * 2 + 3;
                        passdata2 = alloca(len_passdata);
@@ -1050,7 +1049,6 @@ static int sendmail(struct minivm_template *template, struct minivm_account *vmu
                char *passdata;
                int vmlen = strlen(template->subject) * 3 + 200;
                if ((passdata = alloca(vmlen))) {
-                       memset(passdata, 0, vmlen);
                        pbx_substitute_variables_helper(ast, template->subject, passdata, vmlen);
                        fprintf(p, "Subject: %s\n", passdata);
                } else {
@@ -1082,7 +1080,6 @@ static int sendmail(struct minivm_template *template, struct minivm_account *vmu
                char *passdata;
                int vmlen = strlen(template->body)*3 + 200;
                if ((passdata = alloca(vmlen))) {
-                       memset(passdata, 0, vmlen);
                        pbx_substitute_variables_helper(ast, template->body, passdata, vmlen);
                        ast_debug(3, "Message now: %s\n-----\n", passdata);
                        fprintf(p, "%s\n", passdata);
index 13c25d8..3c4ef97 100644 (file)
@@ -220,7 +220,7 @@ static void launch_monitor_thread(struct ast_channel *chan, const char *filename
 {
        pthread_t thread;
        struct mixmonitor *mixmonitor;
-       char postprocess2[1024] = "";
+       char postprocess2[1024];
        size_t len;
 
        len = sizeof(*mixmonitor) + strlen(chan->name) + strlen(filename) + 2;
@@ -235,7 +235,6 @@ static void launch_monitor_thread(struct ast_channel *chan, const char *filename
                                *p2 = '$';
                        }
                }
-
                pbx_substitute_variables_helper(chan, p1, postprocess2, sizeof(postprocess2) - 1);
                if (!ast_strlen_zero(postprocess2))
                        len += strlen(postprocess2) + 1;
index 6754d08..cb49b36 100644 (file)
@@ -202,7 +202,6 @@ static int do_say(say_args_t *a, const char *s, const char *options, int depth)
                ast_trim_blanks(x);
 
                /* replace variables */
-               memset(fn, 0, sizeof(fn)); /* XXX why isn't done in pbx_substitute_variables_helper! */
                pbx_substitute_variables_varshead(&head, x, fn, sizeof(fn));
                ast_log(LOG_WARNING, "doing [%s]\n", fn);
 
index 5ac4c26..92374f8 100644 (file)
@@ -2978,7 +2978,6 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
                                        if (p == tmpid2 + sizeof(tmpid2))
                                                tmpid2[sizeof(tmpid2) - 1] = '\0';
 
-                                       memset(tmpid, 0, sizeof(tmpid));
                                        pbx_substitute_variables_helper(qe->chan, tmpid2, tmpid, sizeof(tmpid) - 1);
                                }
 
@@ -3005,7 +3004,6 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
                                        if (p == meid2 + sizeof(meid2))
                                                meid2[sizeof(meid2) - 1] = '\0';
 
-                                       memset(meid, 0, sizeof(meid));
                                        pbx_substitute_variables_helper(qe->chan, meid2, meid, sizeof(meid) - 1);
                                }
        
index 7d63b96..14831eb 100644 (file)
@@ -6936,7 +6936,7 @@ static int rpt_exec(struct ast_channel *chan, void *data)
                struct ast_hostent ahp;
                struct hostent *hp;
                struct in_addr ia;
-               char hisip[100] = "", nodeip[100];
+               char hisip[100], nodeip[100];
                const char *val;
                char *s, *s1, *s2;
 
index fa4eb11..fe65abd 100644 (file)
@@ -119,7 +119,6 @@ static int custom_log(struct ast_cdr *cdr)
        if (ast_strlen_zero(master))
                return 0;
 
-       memset(buf, 0 , sizeof(buf));
        /* Quite possibly the first use of a static struct ast_channel, we need it so the var funcs will work */
        memset(&dummy, 0, sizeof(dummy));
        dummy.cdr = cdr;
index 6e3dd87..4fa66b5 100644 (file)
@@ -143,7 +143,6 @@ static int manager_log(struct ast_cdr *cdr)
        ast_strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult);
 
        /* Custom fields handling */
-       memset(buf, 0 , sizeof(buf));
        if (customfields != NULL && customfields->used > 0) {
                memset(&dummy, 0, sizeof(dummy));
                dummy.cdr = cdr;
index c6eb8b5..26ec6ff 100644 (file)
@@ -158,7 +158,7 @@ static int sqlite3_log(struct ast_cdr *cdr)
 
        { /* Make it obvious that only sql_cmd should be used outside of this block */
                char *sql_tmp_cmd;
-               char sql_insert_cmd[2048] = "";
+               char sql_insert_cmd[2048];
                sql_tmp_cmd = sqlite3_mprintf("INSERT INTO %q (%q) VALUES (%q)", table, columns, values);
                dummy.cdr = cdr;
                pbx_substitute_variables_helper(&dummy, sql_tmp_cmd, sql_insert_cmd, sizeof(sql_insert_cmd) - 1);
index 82a564b..cf19816 100644 (file)
@@ -141,7 +141,6 @@ static int cut_internal(struct ast_channel *chan, char *data, char *buffer, size
 
                if (tmp) {
                        snprintf(tmp, strlen(args.varname) + 4, "${%s}", args.varname);
-                       memset(varvalue, 0, sizeof(varvalue));
                } else {
                        return ERROR_NOMEM;
                }
index aff358c..4093be8 100644 (file)
@@ -157,7 +157,6 @@ static int acf_import(struct ast_channel *chan, const char *cmd, char *data, cha
                AST_APP_ARG(varname);
        );
        AST_STANDARD_APP_ARGS(args, data);
-       memset(buf, 0, len);
 
        if (!ast_strlen_zero(args.varname)) {
                struct ast_channel *chan2 = ast_get_channel_by_name_locked(args.channel);
index 069eaf7..a2f895b 100644 (file)
@@ -138,7 +138,7 @@ static int acf_odbc_write(struct ast_channel *chan, const char *cmd, char *s, co
 {
        struct odbc_obj *obj = NULL;
        struct acf_odbc_query *query;
-       char *t, buf[2048]="", varname[15];
+       char *t, buf[2048], varname[15];
        int i, dsn, bogus_chan = 0;
        AST_DECLARE_APP_ARGS(values,
                AST_APP_ARG(field)[100];
@@ -256,7 +256,7 @@ static int acf_odbc_read(struct ast_channel *chan, const char *cmd, char *s, cha
 {
        struct odbc_obj *obj = NULL;
        struct acf_odbc_query *query;
-       char sql[2048] = "", varname[15], colnames[2048] = "", rowcount[12] = "-1";
+       char sql[2048], varname[15], colnames[2048] = "", rowcount[12] = "-1";
        int res, x, y, buflen = 0, escapecommas, rowlimit = 1, dsn, bogus_chan = 0;
        AST_DECLARE_APP_ARGS(args,
                AST_APP_ARG(field)[100];
index f4869f4..0ed4bc1 100644 (file)
@@ -48,7 +48,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 static int function_fieldqty(struct ast_channel *chan, const char *cmd,
                             char *parse, char *buf, size_t len)
 {
-       char *varsubst, varval[8192] = "", *varval2 = varval;
+       char *varsubst, varval[8192], *varval2 = varval;
        int fieldcount = 0;
        AST_DECLARE_APP_ARGS(args,
                             AST_APP_ARG(varname);
@@ -734,8 +734,6 @@ static struct ast_custom_function strptime_function = {
 static int function_eval(struct ast_channel *chan, const char *cmd, char *data,
                         char *buf, size_t len)
 {
-       memset(buf, 0, len);
-
        if (ast_strlen_zero(data)) {
                ast_log(LOG_WARNING, "EVAL requires an argument: EVAL(<string>)\n");
                return -1;
index 6faea62..417b515 100644 (file)
@@ -522,7 +522,7 @@ int ast_extension_close(const char *pattern, const char *data, int needmore);
  * \retval -1 on failure.
  */
 int ast_spawn_extension(struct ast_channel *c, const char *context, 
-       const char *exten, int priority, const char *callerid);
+      const char *exten, int priority, const char *callerid, int *found, int combined_find_spawn);
 
 /*! 
  * \brief Add a context include
index 82badbb..4f16852 100644 (file)
@@ -505,7 +505,7 @@ static int rotate_file(const char *filename)
 
        if (!ast_strlen_zero(exec_after_rotate)) {
                struct ast_channel *c = ast_channel_alloc(0, 0, "", "", "", "", "", 0, "Logger/rotate");
-               char buf[512] = "";
+               char buf[512];
                pbx_builtin_setvar_helper(c, "filename", filename);
                pbx_substitute_variables_helper(c, exec_after_rotate, buf, sizeof(buf));
                system(buf);
index 2910219..a3e8248 100644 (file)
@@ -1618,8 +1618,7 @@ int ast_func_write(struct ast_channel *chan, const char *function, const char *v
 
 static void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int count)
 {
-       /* Substitutes variables into cp2, based on string cp1, and assuming cp2 to be
-          zero-filled */
+       /* Substitutes variables into cp2, based on string cp1, cp2 NO LONGER NEEDS TO BE ZEROED OUT!!!!  */
        char *cp4;
        const char *tmp, *whereweare;
        int length, offset, offset2, isfunction;
@@ -1628,7 +1627,8 @@ static void pbx_substitute_variables_helper_full(struct ast_channel *c, struct v
        char *nextvar, *nextexp, *nextthing;
        char *vars, *vare;
        int pos, brackets, needsub, len;
-
+       
+       *cp2 = 0; /* just in case nothing ends up there */
        whereweare=tmp=cp1;
        while (!ast_strlen_zero(whereweare) && count) {
                /* Assume we're copying the whole remaining string */
@@ -1662,6 +1662,7 @@ static void pbx_substitute_variables_helper_full(struct ast_channel *c, struct v
                        count -= pos;
                        cp2 += pos;
                        whereweare += pos;
+                       *cp2 = 0;
                }
 
                if (nextvar) {
@@ -1702,7 +1703,6 @@ static void pbx_substitute_variables_helper_full(struct ast_channel *c, struct v
                                if (!ltmp)
                                        ltmp = alloca(VAR_BUF_SIZE);
 
-                               memset(ltmp, 0, VAR_BUF_SIZE);
                                pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1);
                                vars = ltmp;
                        } else {
@@ -1746,6 +1746,7 @@ static void pbx_substitute_variables_helper_full(struct ast_channel *c, struct v
                                memcpy(cp2, cp4, length);
                                count -= length;
                                cp2 += length;
+                               *cp2 = 0;
                        }
                } else if (nextexp) {
                        /* We have an expression.  Find the start and end, and determine
@@ -1789,7 +1790,6 @@ static void pbx_substitute_variables_helper_full(struct ast_channel *c, struct v
                                if (!ltmp)
                                        ltmp = alloca(VAR_BUF_SIZE);
 
-                               memset(ltmp, 0, VAR_BUF_SIZE);
                                pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1);
                                vars = ltmp;
                        } else {
@@ -1802,6 +1802,7 @@ static void pbx_substitute_variables_helper_full(struct ast_channel *c, struct v
                                ast_debug(1, "Expression result is '%s'\n", cp2);
                                count -= length;
                                cp2 += length;
+                               *cp2 = 0;
                        }
                }
        }
@@ -1820,7 +1821,6 @@ void pbx_substitute_variables_varshead(struct varshead *headp, const char *cp1,
 static void pbx_substitute_variables(char *passdata, int datalen, struct ast_channel *c, struct ast_exten *e)
 {
        const char *tmp;
-       memset(passdata, 0, datalen);
 
        /* Nothing more to do */
        if (!e->data)
@@ -1847,8 +1847,8 @@ static void pbx_substitute_variables(char *passdata, int datalen, struct ast_cha
  * \retval  -1 on failure.
  */
 static int pbx_extension_helper(struct ast_channel *c, struct ast_context *con,
-       const char *context, const char *exten, int priority,
-       const char *label, const char *callerid, enum ext_match_t action)
+  const char *context, const char *exten, int priority,
+  const char *label, const char *callerid, enum ext_match_t action, int *found, int combined_find_spawn)
 {
        struct ast_exten *e;
        struct ast_app *app;
@@ -1857,10 +1857,14 @@ static int pbx_extension_helper(struct ast_channel *c, struct ast_context *con,
        char passdata[EXT_DATA_SIZE];
 
        int matching_action = (action == E_MATCH || action == E_CANMATCH || action == E_MATCHMORE);
-
+       
        ast_rdlock_contexts();
+       if (found)
+               *found = 0;
        e = pbx_find_extension(c, con, &q, context, exten, priority, label, callerid, action);
        if (e) {
+               if (found)
+                       *found = 1;
                if (matching_action) {
                        ast_unlock_contexts();
                        return -1;      /* success, we found it */
@@ -1927,19 +1931,19 @@ static int pbx_extension_helper(struct ast_channel *c, struct ast_context *con,
                ast_unlock_contexts();
                switch (q.status) {
                case STATUS_NO_CONTEXT:
-                       if (!matching_action)
+                       if (!matching_action && !combined_find_spawn)
                                ast_log(LOG_NOTICE, "Cannot find extension context '%s'\n", context);
                        break;
                case STATUS_NO_EXTENSION:
-                       if (!matching_action)
+                       if (!matching_action && !combined_find_spawn)
                                ast_log(LOG_NOTICE, "Cannot find extension '%s' in context '%s'\n", exten, context);
                        break;
                case STATUS_NO_PRIORITY:
-                       if (!matching_action)
+                       if (!matching_action && !combined_find_spawn)
                                ast_log(LOG_NOTICE, "No such priority %d in extension '%s' in context '%s'\n", priority, exten, context);
                        break;
                case STATUS_NO_LABEL:
-                       if (context)
+                       if (context && !combined_find_spawn)
                                ast_log(LOG_NOTICE, "No such label '%s' in extension '%s' in context '%s'\n", label, exten, context);
                        break;
                default:
@@ -2376,32 +2380,32 @@ int ast_get_hint(char *hint, int hintsize, char *name, int namesize, struct ast_
 
 int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
 {
-       return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCH);
+       return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCH, 0, 0);
 }
 
 int ast_findlabel_extension(struct ast_channel *c, const char *context, const char *exten, const char *label, const char *callerid)
 {
-       return pbx_extension_helper(c, NULL, context, exten, 0, label, callerid, E_FINDLABEL);
+       return pbx_extension_helper(c, NULL, context, exten, 0, label, callerid, E_FINDLABEL, 0, 0);
 }
 
 int ast_findlabel_extension2(struct ast_channel *c, struct ast_context *con, const char *exten, const char *label, const char *callerid)
 {
-       return pbx_extension_helper(c, con, NULL, exten, 0, label, callerid, E_FINDLABEL);
+       return pbx_extension_helper(c, con, NULL, exten, 0, label, callerid, E_FINDLABEL, 0, 0);
 }
 
 int ast_canmatch_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
 {
-       return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_CANMATCH);
+       return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_CANMATCH, 0, 0);
 }
 
 int ast_matchmore_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
 {
-       return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCHMORE);
+       return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCHMORE, 0, 0);
 }
 
-int ast_spawn_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
+int ast_spawn_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid, int *found, int combined_find_spawn)
 {
-       return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_SPAWN);
+       return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_SPAWN, found, combined_find_spawn);
 }
 
 /*! helper function to set extension and priority */
@@ -2498,50 +2502,7 @@ static int __ast_pbx_run(struct ast_channel *c)
                int digit = 0;
 
                /* loop on priorities in this context/exten */
-               while (ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) {
-                       found = 1;
-                       if ((res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->cid.cid_num))) {
-                               /* Something bad happened, or a hangup has been requested. */
-                               if (strchr("0123456789ABCDEF*#", res)) {
-                                       ast_debug(1, "Oooh, got something to jump out with ('%c')!\n", res);
-                                       pos = 0;
-                                       dst_exten[pos++] = digit = res;
-                                       dst_exten[pos] = '\0';
-                                       break;
-                               }
-                               if (res == AST_PBX_KEEPALIVE) {
-                                       ast_debug(1, "Spawn extension (%s,%s,%d) exited KEEPALIVE on '%s'\n", c->context, c->exten, c->priority, c->name);
-                                       ast_verb(2, "Spawn extension (%s, %s, %d) exited KEEPALIVE on '%s'\n", c->context, c->exten, c->priority, c->name);
-                                       error = 1;
-                                       break;
-                               }
-                               ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
-                               ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
-
-                               if ((res == AST_PBX_ERROR) && ast_exists_extension(c, c->context, "e", 1, c->cid.cid_num)) {
-                                       /* if we are already on the 'e' exten, don't jump to it again */
-                                       if (!strcmp(c->exten, "e")) {
-                                               if (option_verbose > 1)
-                                                       ast_verbose(VERBOSE_PREFIX_2 "Spawn extension (%s, %s, %d) exited ERROR while already on 'e' exten on '%s'\n", c->context, c->exten, c->priority, c->name);
-                                               error = 1;
-                                               break;
-                                       } else {
-                                               pbx_builtin_raise_exception(c, "ERROR");
-                                               continue;
-                                       }
-                               }
-
-                               if (c->_softhangup == AST_SOFTHANGUP_ASYNCGOTO) {
-                                       c->_softhangup = 0;
-                               } else if (c->_softhangup == AST_SOFTHANGUP_TIMEOUT) {
-                                       /* atimeout, nothing bad */
-                               } else {
-                                       if (c->cdr)
-                                               ast_cdr_update(c);
-                                       error = 1;
-                                       break;
-                               }
-                       }
+               while ( !(res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->cid.cid_num, &found,1))) {
                        if (c->_softhangup == AST_SOFTHANGUP_TIMEOUT && ast_exists_extension(c, c->context, "T", 1, c->cid.cid_num)) {
                                set_ext_pri(c, "T", 0); /* 0 will become 1 with the c->priority++; at the end */
                                /* If the AbsoluteTimeout is not reset to 0, we'll get an infinite loop */
@@ -2560,6 +2521,45 @@ static int __ast_pbx_run(struct ast_channel *c)
                        }
                        c->priority++;
                } /* end while  - from here on we can use 'break' to go out */
+               if (found && res) {
+                       /* Something bad happened, or a hangup has been requested. */
+                       if (strchr("0123456789ABCDEF*#", res)) {
+                               ast_debug(1, "Oooh, got something to jump out with ('%c')!\n", res);
+                               pos = 0;
+                               dst_exten[pos++] = digit = res;
+                               dst_exten[pos] = '\0';
+                       }
+                       if (res == AST_PBX_KEEPALIVE) {
+                               ast_debug(1, "Spawn extension (%s,%s,%d) exited KEEPALIVE on '%s'\n", c->context, c->exten, c->priority, c->name);
+                               ast_verb(2, "Spawn extension (%s, %s, %d) exited KEEPALIVE on '%s'\n", c->context, c->exten, c->priority, c->name);
+                               error = 1;
+                       }
+                       ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
+                       ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
+                       
+                       if ((res == AST_PBX_ERROR) && ast_exists_extension(c, c->context, "e", 1, c->cid.cid_num)) {
+                               /* if we are already on the 'e' exten, don't jump to it again */
+                               if (!strcmp(c->exten, "e")) {
+                                       if (option_verbose > 1)
+                                               ast_verbose(VERBOSE_PREFIX_2 "Spawn extension (%s, %s, %d) exited ERROR while already on 'e' exten on '%s'\n", c->context, c->exten, c->priority, c->name);
+                                       error = 1;
+                               } else {
+                                       pbx_builtin_raise_exception(c, "ERROR");
+                                       continue;
+                               }
+                       }
+                       
+                       if (c->_softhangup == AST_SOFTHANGUP_ASYNCGOTO) {
+                               c->_softhangup = 0;
+                       } else if (c->_softhangup == AST_SOFTHANGUP_TIMEOUT) {
+                               /* atimeout, nothing bad */
+                       } else {
+                               if (c->cdr)
+                                       ast_cdr_update(c);
+                               error = 1;
+                               break;
+                       }
+               }
                if (error)
                        break;
 
@@ -2657,15 +2657,14 @@ static int __ast_pbx_run(struct ast_channel *c)
                if (c->cdr && ast_opt_end_cdr_before_h_exten)
                        ast_cdr_end(c->cdr);
                set_ext_pri(c, "h", 1);
-               while (ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) {
-                       if ((res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->cid.cid_num))) {
-                               /* Something bad happened, or a hangup has been requested. */
-                               ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
-                               ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
-                               break;
-                       }
+               while ((res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->cid.cid_num, &found,1))) {
                        c->priority++;
                }
+               if (found && res) {
+                       /* Something bad happened, or a hangup has been requested. */
+                       ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
+                       ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
+               }
        }
        ast_set2_flag(c, autoloopflag, AST_FLAG_IN_AUTOLOOP);
 
@@ -4930,7 +4929,7 @@ int ast_add_extension2(struct ast_context *con,
        int res;
        int length;
        char *p;
-       char expand_buf[VAR_BUF_SIZE] = { 0, };
+       char expand_buf[VAR_BUF_SIZE];
 
        /* if we are adding a hint, and there are global variables, and the hint
           contains variable references, then expand them
@@ -6078,7 +6077,7 @@ int pbx_builtin_importvar(struct ast_channel *chan, void *data)
        char *name;
        char *value;
        char *channel;
-       char tmp[VAR_BUF_SIZE]="";
+       char tmp[VAR_BUF_SIZE];
        static int deprecation_warning = 0;
 
        if (ast_strlen_zero(data)) {
index 9b112dc..0a62da7 100644 (file)
@@ -1390,7 +1390,6 @@ static int pbx_load_config(const char *config_file)
                ast_copy_string(userscontext, "default", sizeof(userscontext));
                                                                    
        for (v = ast_variable_browse(cfg, "globals"); v; v = v->next) {
-               memset(realvalue, 0, sizeof(realvalue));
                pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
                pbx_builtin_setvar_helper(NULL, v->name, realvalue);
        }
@@ -1487,20 +1486,17 @@ static int pbx_load_config(const char *config_file)
                                        free(tc);
                                }
                        } else if (!strcasecmp(v->name, "include")) {
-                               memset(realvalue, 0, sizeof(realvalue));
                                pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
                                if (ast_context_add_include2(con, realvalue, registrar))
                                        ast_log(LOG_WARNING, "Unable to include context '%s' in context '%s'\n", v->value, cxt);
                        } else if (!strcasecmp(v->name, "ignorepat")) {
-                               memset(realvalue, 0, sizeof(realvalue));
                                pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
                                if (ast_context_add_ignorepat2(con, realvalue, registrar))
                                        ast_log(LOG_WARNING, "Unable to include ignorepat '%s' in context '%s'\n", v->value, cxt);
                        } else if (!strcasecmp(v->name, "switch") || !strcasecmp(v->name, "lswitch") || !strcasecmp(v->name, "eswitch")) {
                                char *stringp = realvalue;
                                char *appl, *data;
-
-                               memset(realvalue, 0, sizeof(realvalue));
+                               
                                if (!strcasecmp(v->name, "switch"))
                                        pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
                                else
index 05d9573..7f3e066 100644 (file)
@@ -533,7 +533,7 @@ struct dundi_query_state {
 
 static int get_mapping_weight(struct dundi_mapping *map)
 {
-       char buf[32] = "";
+       char buf[32];
 
        if (map->weightstr) {
                pbx_substitute_variables_helper(NULL, map->weightstr, buf, sizeof(buf) - 1);
index dcbef90..3221fb6 100644 (file)
@@ -87,7 +87,6 @@ static char *loopback_helper(char *buf, int buflen, const char *exten, const cha
        char tmp[80];
 
        snprintf(tmp, sizeof(tmp), "%d", priority);
-       memset(buf, 0, buflen);
        AST_LIST_HEAD_INIT_NOLOCK(&headp);
        AST_LIST_INSERT_HEAD(&headp, ast_var_assign("EXTEN", exten), entries);
        AST_LIST_INSERT_HEAD(&headp, ast_var_assign("CONTEXT", context), entries);
@@ -141,8 +140,9 @@ static int loopback_canmatch(struct ast_channel *chan, const char *context, cons
 
 static int loopback_exec(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
 {
+       int found;
        LOOPBACK_COMMON;
-       res = ast_spawn_extension(chan, newcontext, newexten, newpriority, callerid);
+       res = ast_spawn_extension(chan, newcontext, newexten, newpriority, callerid, &found, 0);
        /* XXX hmmm... res is overridden ? */
        if (newpattern && !ast_extension_match(newpattern, exten))
                res = -1;
index 31d266d..d733dc0 100644 (file)
@@ -191,7 +191,7 @@ static int realtime_exec(struct ast_channel *chan, const char *context, const ch
                if (!ast_strlen_zero(app)) {
                        struct ast_app *a = pbx_findapp(app);
                        if (a) {
-                               char appdata[512]="";
+                               char appdata[512];
                                char tmp1[80];
                                char tmp2[80];
                                char tmp3[EXT_DATA_SIZE];
index 4c26d1a..5deb018 100644 (file)
@@ -3788,7 +3788,6 @@ void add_extensions(struct ael_extension *exten)
        do {
                struct ael_priority *last = 0;
                
-               memset(realext, '\0', sizeof(realext)); /* make sure this is properly initialized */
                pbx_substitute_variables_helper(NULL, exten->name, realext, sizeof(realext) - 1);
                if (exten->hints) {
                        if (ast_add_extension2(exten->context, 0 /*no replace*/, realext, PRIORITY_HINT, NULL, exten->cidmatch, 
index 8f722f0..80dd168 100644 (file)
@@ -1192,7 +1192,7 @@ static int handle_getvariable(struct ast_channel *chan, AGI *agi, int argc, char
 
 static int handle_getvariablefull(struct ast_channel *chan, AGI *agi, int argc, char **argv)
 {
-       char tmp[4096] = "";
+       char tmp[4096];
        struct ast_channel *chan2=NULL;
 
        if ((argc != 4) && (argc != 5))
index 0d30cc9..fa31102 100644 (file)
@@ -5700,6 +5700,7 @@ static void pbx_substitute_variables_helper_full(struct ast_channel *c, struct v
        char *vars, *vare;
        int pos, brackets, needsub, len;
 
+       *cp2 = 0; /* just in case there's nothing to do */
        whereweare=tmp=cp1;
        while (!ast_strlen_zero(whereweare) && count) {
                /* Assume we're copying the whole remaining string */
@@ -5731,6 +5732,7 @@ static void pbx_substitute_variables_helper_full(struct ast_channel *c, struct v
                        count -= pos;
                        cp2 += pos;
                        whereweare += pos;
+                       *cp2 = 0;
                }
 
                if (nextvar) {
@@ -5802,6 +5804,7 @@ static void pbx_substitute_variables_helper_full(struct ast_channel *c, struct v
                                memcpy(cp2, cp4, length);
                                count -= length;
                                cp2 += length;
+                               *cp2 = 0;
                        }
                } else if (nextexp) {
                        /* We have an expression.  Find the start and end, and determine
@@ -5859,6 +5862,7 @@ static void pbx_substitute_variables_helper_full(struct ast_channel *c, struct v
                                        ast_log(LOG_DEBUG, "Expression result is '%s'\n", cp2);
                                count -= length;
                                cp2 += length;
+                               *cp2 = 0;
                        }
                } else
                        break;