} 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;
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;
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;
}
#define AST_FLAG_BLOCKING (1 << 3) /* if we are blocking */
#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_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_NBRIDGE (1 << 8) /* is it in a native bridge */
+#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_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_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;
int pos;
int waittime;
int res=0;
+ int autoloopflag;
/* A little initial setup here */
if (c->pbx)
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);
}
} else {
char *status;
+
status = pbx_builtin_getvar_helper(c, "DIALSTATUS");
if (!status)
status = "UNKNOWN";
c->priority++;
}
}
+ ast_set2_flag(c, autoloopflag, AST_FLAG_IN_AUTOLOOP);
pbx_destroy(c->pbx);
c->pbx = NULL;
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
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);
}
-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) {
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);
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;
}
-
-