diff --git a/apps/app_dial.c b/apps/app_dial.c index 2b90e9c389..d5b46dfd1e 100755 --- a/apps/app_dial.c +++ b/apps/app_dial.c @@ -201,24 +201,19 @@ static void hanguptree(struct localuser *outgoing, struct ast_channel *exception } while (0) -static int ast_onedigit_goto(struct ast_channel *chan, char *context, char exten, int pri, char *cid) +static int onedigit_goto(struct ast_channel *chan, char *context, char exten, int pri) { - char rexten[2]; - snprintf(rexten, 2, "%c", exten); + char rexten[2] = { exten, '\0' }; + if (context) { - if (ast_exists_extension(chan, context, rexten, pri, cid)) { - ast_explicit_goto(chan, context, rexten, pri-1); + if (ast_goto_if_exists(chan, context, rexten, pri)) return 1; - } } else { - if (ast_exists_extension(chan, chan->context, rexten, pri, cid)) { - ast_explicit_goto(chan, chan->context, rexten, pri-1); + if (ast_goto_if_exists(chan, chan->context, rexten, pri)) return 1; - } else if (!ast_strlen_zero(chan->macrocontext)) { - if (ast_exists_extension(chan, chan->macrocontext, rexten, pri, cid)) { - ast_explicit_goto(chan, chan->macrocontext, rexten, pri-1); + else if (!ast_strlen_zero(chan->macrocontext)) { + if (ast_goto_if_exists(chan, chan->macrocontext, rexten, pri)) return 1; - } } } return 0; @@ -552,7 +547,7 @@ static struct ast_channel *wait_for_answer(struct ast_channel *in, struct localu if (f && (f->frametype == AST_FRAME_DTMF)) { if (ast_test_flag(peerflags, DIAL_HALT_ON_DTMF)) { context = pbx_builtin_getvar_helper(in, "EXITCONTEXT"); - if (ast_onedigit_goto(in, context, (char) f->subclass, 1, in->cid.cid_num)) { + if (onedigit_goto(in, context, (char) f->subclass, 1)) { if (option_verbose > 3) ast_verbose(VERBOSE_PREFIX_3 "User hit %c to disconnect call.\n", f->subclass); *to=0; @@ -1448,7 +1443,7 @@ static int retrydial_exec(struct ast_channel *chan, void *data) if (res < 0) break; else if (res > 0) { /* Trying to send the call elsewhere (1 digit ext) */ - if (ast_onedigit_goto(chan, context, (char) res, 1, chan->cid.cid_num)) { + if (onedigit_goto(chan, context, (char) res, 1)) { res = 0; break; } diff --git a/apps/app_macro.c b/apps/app_macro.c index f0b37aed33..43ad368366 100755 --- a/apps/app_macro.c +++ b/apps/app_macro.c @@ -88,6 +88,7 @@ static int macro_exec(struct ast_channel *chan, void *data) char *offsets; int offset; int setmacrocontext=0; + int autoloopflag; char *save_macro_exten; char *save_macro_context; @@ -166,6 +167,8 @@ static int macro_exec(struct ast_channel *chan, void *data) pbx_builtin_setvar_helper(chan, varname, cur); argc++; } + autoloopflag = ast_test_flag(chan, AST_FLAG_IN_AUTOLOOP); + ast_set_flag(chan, AST_FLAG_IN_AUTOLOOP); while(ast_exists_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))) { /* Something bad happened, or a hangup has been requested. */ @@ -208,6 +211,7 @@ static int macro_exec(struct ast_channel *chan, void *data) chan->priority++; } out: + ast_set2_flag(chan, autoloopflag, AST_FLAG_IN_AUTOLOOP); for (x=1; xpriority is set, it will get incremented before + finding the next priority to run + */ #define AST_FEATURE_PLAY_WARNING (1 << 0) #define AST_FEATURE_REDIRECT (1 << 1) #define AST_FEATURE_DISCONNECT (1 << 2) -#define AST_FEATURE_ATXFER (1 << 3) -#define AST_FEATURE_AUTOMON (1 << 4) +#define AST_FEATURE_ATXFER (1 << 3) +#define AST_FEATURE_AUTOMON (1 << 4) -#define AST_FEATURE_FLAG_NEEDSDTMF (1 << 0) +#define AST_FEATURE_FLAG_NEEDSDTMF (1 << 0) struct ast_bridge_config { struct ast_flags features_caller; diff --git a/pbx.c b/pbx.c index b721d4b0aa..79a903480f 100755 --- a/pbx.c +++ b/pbx.c @@ -2243,6 +2243,7 @@ int ast_pbx_run(struct ast_channel *c) int pos; int waittime; int res=0; + int autoloopflag; /* A little initial setup here */ if (c->pbx) @@ -2268,9 +2269,12 @@ int ast_pbx_run(struct ast_channel *c) c->pbx->rtimeout = 10; c->pbx->dtimeout = 5; + autoloopflag = ast_test_flag(c, AST_FLAG_IN_AUTOLOOP); + ast_set_flag(c, AST_FLAG_IN_AUTOLOOP); + /* Start by trying whatever the channel is set to */ if (!ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) { - /* JK02: If not successfull fall back to 's' */ + /* If not successful fall back to 's' */ if (option_verbose > 1) ast_verbose( VERBOSE_PREFIX_2 "Starting %s at %s,%s,%d failed so falling back to exten 's'\n", c->name, c->context, c->exten, c->priority); strncpy(c->exten, "s", sizeof(c->exten)-1); @@ -2420,6 +2424,7 @@ int ast_pbx_run(struct ast_channel *c) } } else { char *status; + status = pbx_builtin_getvar_helper(c, "DIALSTATUS"); if (!status) status = "UNKNOWN"; @@ -2454,6 +2459,7 @@ out: c->priority++; } } + ast_set2_flag(c, autoloopflag, AST_FLAG_IN_AUTOLOOP); pbx_destroy(c->pbx); c->pbx = NULL; @@ -4415,27 +4421,34 @@ int ast_add_extension(const char *context, int replace, const char *extension, i return -1; } -int ast_explicit_goto(struct ast_channel *chan, const char *context, const char *exten, int priority) { - if(chan) { - if (context && !ast_strlen_zero(context)) - strncpy(chan->context, context, sizeof(chan->context) - 1); - if (exten && !ast_strlen_zero(exten)) - strncpy(chan->exten, exten, sizeof(chan->context) - 1); - if(priority > -1) - chan->priority = priority; - return 0; +int ast_explicit_goto(struct ast_channel *chan, const char *context, const char *exten, int priority) +{ + if (!chan) + return -1; + + if (context && !ast_strlen_zero(context)) + strncpy(chan->context, context, sizeof(chan->context) - 1); + if (exten && !ast_strlen_zero(exten)) + strncpy(chan->exten, exten, sizeof(chan->exten) - 1); + if (priority > -1) { + chan->priority = priority; + /* see flag description in channel.h for explanation */ + if (ast_test_flag(chan, AST_FLAG_IN_AUTOLOOP)) + chan->priority--; } - return -1; + + return 0; } int ast_async_goto(struct ast_channel *chan, const char *context, const char *exten, int priority) { int res = 0; + ast_mutex_lock(&chan->lock); if (chan->pbx) { /* This channel is currently in the PBX */ - ast_explicit_goto(chan, context, exten, priority - 1); + ast_explicit_goto(chan, context, exten, priority); ast_softhangup_nolock(chan, AST_SOFTHANGUP_ASYNCGOTO); } else { /* In order to do it when the channel doesn't really exist within @@ -4451,9 +4464,9 @@ int ast_async_goto(struct ast_channel *chan, const char *context, const char *ex tmpchan->writeformat = chan->writeformat; /* Setup proper location */ ast_explicit_goto(tmpchan, - (context && !ast_strlen_zero(context)) ? context : chan->context, - (exten && !ast_strlen_zero(exten)) ? exten : chan->exten, - priority); + (context && !ast_strlen_zero(context)) ? context : chan->context, + (exten && !ast_strlen_zero(exten)) ? exten : chan->exten, + priority); /* Masquerade into temp channel */ ast_channel_masquerade(tmpchan, chan); @@ -6188,35 +6201,21 @@ int ast_context_verify_includes(struct ast_context *con) } -static int __ast_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int priority, int async) +static int __ast_goto_if_exists(struct ast_channel *chan, char *context, char *exten, int priority, int async) { - int (*goto_func)(struct ast_channel *chan, const char *context, const char *exten, int priority) = NULL; - - if(chan) { + int (*goto_func)(struct ast_channel *chan, const char *context, const char *exten, int priority); - if (async) { - goto_func = ast_async_goto; - } else { - goto_func = ast_explicit_goto; - priority--; - if(priority < 0) - priority = 0; - } + if (!chan) + return -2; - if (ast_exists_extension(chan, - context ? context : chan->context, - exten ? exten : chan->exten, - priority, - chan->cid.cid_num)) { - return goto_func(chan, - context ? context : chan->context, - exten ? exten : chan->exten, - priority); - } else - return -3; - } - - return -2; + goto_func = (async) ? ast_async_goto : ast_explicit_goto; + if (ast_exists_extension(chan, context ? context : chan->context, + exten ? exten : chan->exten, priority, + chan->cid.cid_num)) + return goto_func(chan, context ? context : chan->context, + exten ? exten : chan->exten, priority); + else + return -3; } int ast_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int priority) { @@ -6264,7 +6263,7 @@ int ast_parseable_goto(struct ast_channel *chan, const char *goto_string) mode = -1; pri++; } - if (sscanf(pri, "%i", &ipri) != 1) { + if (sscanf(pri, "%d", &ipri) != 1) { if ((ipri = ast_findlabel_extension(chan, context ? context : chan->context, (exten && strcasecmp(exten, "BYEXTENSION")) ? exten : chan->exten, pri, chan->cid.cid_num)) < 1) { ast_log(LOG_WARNING, "Priority '%s' must be a number > 0, or valid label\n", pri); @@ -6280,10 +6279,8 @@ int ast_parseable_goto(struct ast_channel *chan, const char *goto_string) if (mode) ipri = chan->priority + (ipri * mode); - ast_explicit_goto(chan, context, exten, chan->pbx ? ipri - 1 : ipri); + ast_explicit_goto(chan, context, exten, ipri); ast_cdr_update(chan); return 0; } - -