make 'goto' APIs aware of auto-processing loops, so they know exactly when to set the requested priority or one priority lower

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5529 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Kevin P. Fleming
2005-04-29 15:04:26 +00:00
parent 8cd6529426
commit bced63033d
4 changed files with 65 additions and 65 deletions

View File

@@ -201,24 +201,19 @@ static void hanguptree(struct localuser *outgoing, struct ast_channel *exception
} while (0) } 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]; char rexten[2] = { exten, '\0' };
snprintf(rexten, 2, "%c", exten);
if (context) { if (context) {
if (ast_exists_extension(chan, context, rexten, pri, cid)) { if (ast_goto_if_exists(chan, context, rexten, pri))
ast_explicit_goto(chan, context, rexten, pri-1);
return 1; return 1;
}
} else { } else {
if (ast_exists_extension(chan, chan->context, rexten, pri, cid)) { if (ast_goto_if_exists(chan, chan->context, rexten, pri))
ast_explicit_goto(chan, chan->context, rexten, pri-1);
return 1; return 1;
} else if (!ast_strlen_zero(chan->macrocontext)) { else if (!ast_strlen_zero(chan->macrocontext)) {
if (ast_exists_extension(chan, chan->macrocontext, rexten, pri, cid)) { if (ast_goto_if_exists(chan, chan->macrocontext, rexten, pri))
ast_explicit_goto(chan, chan->macrocontext, rexten, pri-1);
return 1; return 1;
}
} }
} }
return 0; 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 (f && (f->frametype == AST_FRAME_DTMF)) {
if (ast_test_flag(peerflags, DIAL_HALT_ON_DTMF)) { if (ast_test_flag(peerflags, DIAL_HALT_ON_DTMF)) {
context = pbx_builtin_getvar_helper(in, "EXITCONTEXT"); 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) if (option_verbose > 3)
ast_verbose(VERBOSE_PREFIX_3 "User hit %c to disconnect call.\n", f->subclass); ast_verbose(VERBOSE_PREFIX_3 "User hit %c to disconnect call.\n", f->subclass);
*to=0; *to=0;
@@ -1448,7 +1443,7 @@ static int retrydial_exec(struct ast_channel *chan, void *data)
if (res < 0) if (res < 0)
break; break;
else if (res > 0) { /* Trying to send the call elsewhere (1 digit ext) */ 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; res = 0;
break; break;
} }

View File

@@ -88,6 +88,7 @@ static int macro_exec(struct ast_channel *chan, void *data)
char *offsets; char *offsets;
int offset; int offset;
int setmacrocontext=0; int setmacrocontext=0;
int autoloopflag;
char *save_macro_exten; char *save_macro_exten;
char *save_macro_context; 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); pbx_builtin_setvar_helper(chan, varname, cur);
argc++; 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)) { 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))) { 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. */ /* 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++; chan->priority++;
} }
out: out:
ast_set2_flag(chan, autoloopflag, AST_FLAG_IN_AUTOLOOP);
for (x=1; x<argc; x++) { for (x=1; x<argc; x++) {
/* Restore old arguments and delete ours */ /* Restore old arguments and delete ours */
snprintf(varname, sizeof(varname), "ARG%d", x); snprintf(varname, sizeof(varname), "ARG%d", x);

View File

@@ -348,17 +348,21 @@ struct ast_channel {
#define AST_FLAG_BLOCKING (1 << 3) /* if we are blocking */ #define AST_FLAG_BLOCKING (1 << 3) /* if we are blocking */
#define AST_FLAG_ZOMBIE (1 << 4) /* if we are a zombie */ #define AST_FLAG_ZOMBIE (1 << 4) /* if we are a zombie */
#define AST_FLAG_EXCEPTION (1 << 5) /* if there is a pending exception */ #define AST_FLAG_EXCEPTION (1 << 5) /* if there is a pending exception */
#define AST_FLAG_MOH (1 << 6) /* XXX anthm promises me this will disappear XXX listening to moh */ #define AST_FLAG_MOH (1 << 6) /* XXX anthm promises me this will disappear XXX listening to moh */
#define AST_FLAG_SPYING (1 << 7) /* XXX might also go away XXX is spying on someone */ #define AST_FLAG_SPYING (1 << 7) /* XXX might also go away XXX is spying on someone */
#define AST_FLAG_NBRIDGE (1 << 8) /* is it in a native bridge */ #define AST_FLAG_NBRIDGE (1 << 8) /* is it in a native bridge */
#define AST_FLAG_IN_AUTOLOOP (1 << 9) /* the channel is in an auto-incrementing dialplan processor,
so when ->priority is set, it will get incremented before
finding the next priority to run
*/
#define AST_FEATURE_PLAY_WARNING (1 << 0) #define AST_FEATURE_PLAY_WARNING (1 << 0)
#define AST_FEATURE_REDIRECT (1 << 1) #define AST_FEATURE_REDIRECT (1 << 1)
#define AST_FEATURE_DISCONNECT (1 << 2) #define AST_FEATURE_DISCONNECT (1 << 2)
#define AST_FEATURE_ATXFER (1 << 3) #define AST_FEATURE_ATXFER (1 << 3)
#define AST_FEATURE_AUTOMON (1 << 4) #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_bridge_config {
struct ast_flags features_caller; struct ast_flags features_caller;

87
pbx.c
View File

@@ -2243,6 +2243,7 @@ int ast_pbx_run(struct ast_channel *c)
int pos; int pos;
int waittime; int waittime;
int res=0; int res=0;
int autoloopflag;
/* A little initial setup here */ /* A little initial setup here */
if (c->pbx) if (c->pbx)
@@ -2268,9 +2269,12 @@ int ast_pbx_run(struct ast_channel *c)
c->pbx->rtimeout = 10; c->pbx->rtimeout = 10;
c->pbx->dtimeout = 5; 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 */ /* Start by trying whatever the channel is set to */
if (!ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) { 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) 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); 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); strncpy(c->exten, "s", sizeof(c->exten)-1);
@@ -2420,6 +2424,7 @@ int ast_pbx_run(struct ast_channel *c)
} }
} else { } else {
char *status; char *status;
status = pbx_builtin_getvar_helper(c, "DIALSTATUS"); status = pbx_builtin_getvar_helper(c, "DIALSTATUS");
if (!status) if (!status)
status = "UNKNOWN"; status = "UNKNOWN";
@@ -2454,6 +2459,7 @@ out:
c->priority++; c->priority++;
} }
} }
ast_set2_flag(c, autoloopflag, AST_FLAG_IN_AUTOLOOP);
pbx_destroy(c->pbx); pbx_destroy(c->pbx);
c->pbx = NULL; c->pbx = NULL;
@@ -4415,27 +4421,34 @@ int ast_add_extension(const char *context, int replace, const char *extension, i
return -1; return -1;
} }
int ast_explicit_goto(struct ast_channel *chan, const char *context, const char *exten, int priority) { int ast_explicit_goto(struct ast_channel *chan, const char *context, const char *exten, int priority)
if(chan) { {
if (context && !ast_strlen_zero(context)) if (!chan)
strncpy(chan->context, context, sizeof(chan->context) - 1); return -1;
if (exten && !ast_strlen_zero(exten))
strncpy(chan->exten, exten, sizeof(chan->context) - 1); if (context && !ast_strlen_zero(context))
if(priority > -1) strncpy(chan->context, context, sizeof(chan->context) - 1);
chan->priority = priority; if (exten && !ast_strlen_zero(exten))
return 0; 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 ast_async_goto(struct ast_channel *chan, const char *context, const char *exten, int priority)
{ {
int res = 0; int res = 0;
ast_mutex_lock(&chan->lock); ast_mutex_lock(&chan->lock);
if (chan->pbx) { if (chan->pbx) {
/* This channel is currently in the 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); ast_softhangup_nolock(chan, AST_SOFTHANGUP_ASYNCGOTO);
} else { } else {
/* In order to do it when the channel doesn't really exist within /* 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; tmpchan->writeformat = chan->writeformat;
/* Setup proper location */ /* Setup proper location */
ast_explicit_goto(tmpchan, ast_explicit_goto(tmpchan,
(context && !ast_strlen_zero(context)) ? context : chan->context, (context && !ast_strlen_zero(context)) ? context : chan->context,
(exten && !ast_strlen_zero(exten)) ? exten : chan->exten, (exten && !ast_strlen_zero(exten)) ? exten : chan->exten,
priority); priority);
/* Masquerade into temp channel */ /* Masquerade into temp channel */
ast_channel_masquerade(tmpchan, chan); 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; int (*goto_func)(struct ast_channel *chan, const char *context, const char *exten, int priority);
if(chan) { if (!chan)
return -2;
if (async) { goto_func = (async) ? ast_async_goto : ast_explicit_goto;
goto_func = ast_async_goto; if (ast_exists_extension(chan, context ? context : chan->context,
} else { exten ? exten : chan->exten, priority,
goto_func = ast_explicit_goto; chan->cid.cid_num))
priority--; return goto_func(chan, context ? context : chan->context,
if(priority < 0) exten ? exten : chan->exten, priority);
priority = 0; else
} return -3;
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;
} }
int ast_goto_if_exists(struct ast_channel *chan, char* context, char *exten, int priority) { 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; mode = -1;
pri++; 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, if ((ipri = ast_findlabel_extension(chan, context ? context : chan->context, (exten && strcasecmp(exten, "BYEXTENSION")) ? exten : chan->exten,
pri, chan->cid.cid_num)) < 1) { pri, chan->cid.cid_num)) < 1) {
ast_log(LOG_WARNING, "Priority '%s' must be a number > 0, or valid label\n", pri); 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) if (mode)
ipri = chan->priority + (ipri * 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); ast_cdr_update(chan);
return 0; return 0;
} }