as discussed with Mark a few weeks ago, the 'newstack' argument

in pbx_exec is always 1 so it can be removed.

This change also takes away ast_exec_extension(), and lets all
switch functions (exists, canmatch, exec, matchmore) all use the same
prototype, which makes the code a bit cleaner.



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@16558 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.4
Luigi Rizzo 20 years ago
parent c6d1bfbb31
commit 6c232811c0

@ -1449,7 +1449,7 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags
if (*ch == '^') if (*ch == '^')
*ch = '|'; *ch = '|';
} }
res = pbx_exec(peer, app, opt_args[OPT_ARG_CALLEE_MACRO], 1); res = pbx_exec(peer, app, opt_args[OPT_ARG_CALLEE_MACRO]);
ast_log(LOG_DEBUG, "Macro exited with status %d\n", res); ast_log(LOG_DEBUG, "Macro exited with status %d\n", res);
res = 0; res = 0;
} else { } else {

@ -82,7 +82,7 @@ static int exec_exec(struct ast_channel *chan, void *data)
if (appname) { if (appname) {
app = pbx_findapp(appname); app = pbx_findapp(appname);
if (app) { if (app) {
res = pbx_exec(chan, app, args, 1); res = pbx_exec(chan, app, args);
} else { } else {
ast_log(LOG_WARNING, "Could not find application (%s)\n", appname); ast_log(LOG_WARNING, "Could not find application (%s)\n", appname);
res = -1; res = -1;

@ -1143,7 +1143,7 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int c
app = pbx_findapp("agi"); app = pbx_findapp("agi");
if (app) { if (app) {
char *s = ast_strdupa(agifile); char *s = ast_strdupa(agifile);
ret = pbx_exec(chan, app, s, 1); ret = pbx_exec(chan, app, s);
} else { } else {
ast_log(LOG_WARNING, "Could not find application (agi)\n"); ast_log(LOG_WARNING, "Could not find application (agi)\n");
ret = -2; ret = -2;

@ -186,7 +186,7 @@ static int page_exec(struct ast_channel *chan, void *data)
} }
if (!res) { if (!res) {
snprintf(meetmeopts, sizeof(meetmeopts), "%ud|A%sqxd", confid, ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "t"); snprintf(meetmeopts, sizeof(meetmeopts), "%ud|A%sqxd", confid, ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "t");
pbx_exec(chan, app, meetmeopts, 1); pbx_exec(chan, app, meetmeopts);
} }
LOCAL_USER_REMOVE(u); LOCAL_USER_REMOVE(u);

@ -3422,7 +3422,7 @@ static int forward_message(struct ast_channel *chan, char *context, char *dir, i
old_priority = chan->priority; old_priority = chan->priority;
/* call the the Directory, changes the channel */ /* call the the Directory, changes the channel */
res = pbx_exec(chan, app, context ? context : "default", 1); res = pbx_exec(chan, app, context ? context : "default");
ast_copy_string(username, chan->exten, sizeof(username)); ast_copy_string(username, chan->exten, sizeof(username));

@ -101,7 +101,7 @@ static int execif_exec(struct ast_channel *chan, void *data) {
if (ast_true(expr)) { if (ast_true(expr)) {
if ((app = pbx_findapp(myapp))) { if ((app = pbx_findapp(myapp))) {
res = pbx_exec(chan, app, mydata, 1); res = pbx_exec(chan, app, mydata);
} else { } else {
ast_log(LOG_WARNING, "Count not find application! (%s)\n", myapp); ast_log(LOG_WARNING, "Count not find application! (%s)\n", myapp);
res = -1; res = -1;

@ -9573,7 +9573,7 @@ static int iax2_matchmore(struct ast_channel *chan, const char *context, const c
} }
/*! \brief Execute IAX2 dialplan switch */ /*! \brief Execute IAX2 dialplan switch */
static int iax2_exec(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, int newstack, const char *data) static int iax2_exec(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
{ {
char odata[256]; char odata[256];
char req[256]; char req[256];
@ -9589,7 +9589,7 @@ static int iax2_exec(struct ast_channel *chan, const char *context, const char *
if (dialstatus) { if (dialstatus) {
dial = pbx_findapp(dialstatus); dial = pbx_findapp(dialstatus);
if (dial) if (dial)
pbx_exec(chan, dial, "", newstack); pbx_exec(chan, dial, "");
} }
return -1; return -1;
} else if (priority != 1) } else if (priority != 1)
@ -9618,7 +9618,7 @@ static int iax2_exec(struct ast_channel *chan, const char *context, const char *
ast_mutex_unlock(&dpcache_lock); ast_mutex_unlock(&dpcache_lock);
dial = pbx_findapp("Dial"); dial = pbx_findapp("Dial");
if (dial) { if (dial) {
return pbx_exec(chan, dial, req, newstack); return pbx_exec(chan, dial, req);
} else { } else {
ast_log(LOG_WARNING, "No dial application registered\n"); ast_log(LOG_WARNING, "No dial application registered\n");
} }

@ -317,10 +317,8 @@ struct ast_channel {
/*! Procedure causing blocking */ /*! Procedure causing blocking */
const char *blockproc; const char *blockproc;
/*! Current application */ const char *appl; /*! Current application */
char *appl; const char *data; /*! Data passed to current application */
/*! Data passed to current application */
char *data;
/*! Which fd had an event detected on */ /*! Which fd had an event detected on */
int fdno; int fdno;

@ -82,22 +82,20 @@ struct ast_custom_function {
struct ast_custom_function *next; struct ast_custom_function *next;
}; };
/*! \brief All switch functions have the same interface, so define a type for them */
typedef int (ast_switch_f)(struct ast_channel *chan, const char *context,
const char *exten, int priority, const char *callerid, const char *data);
/*! Data structure associated with an asterisk switch */ /*! Data structure associated with an asterisk switch */
struct ast_switch { struct ast_switch {
/*! NULL */
struct ast_switch *next; struct ast_switch *next;
/*! Name of the switch */ const char *name; /*! Name of the switch */
const char *name; const char *description; /*! Description of the switch */
/*! Description of the switch */
const char *description;
int (*exists)(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data);
int (*canmatch)(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data);
int (*exec)(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, int newstack, const char *data); ast_switch_f *exists;
ast_switch_f *canmatch;
int (*matchmore)(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data); ast_switch_f *exec;
ast_switch_f *matchmore;
}; };
struct ast_timing { struct ast_timing {
@ -160,7 +158,6 @@ struct ast_app *pbx_findapp(const char *app);
* \param c channel to execute on * \param c channel to execute on
* \param app which app to execute * \param app which app to execute
* \param data the data passed into the app * \param data the data passed into the app
* \param newstack stack pointer
* *
* This application executes an application on a given channel. It * This application executes an application on a given channel. It
* saves the stack and executes the given appliation passing in * saves the stack and executes the given appliation passing in
@ -168,7 +165,7 @@ struct ast_app *pbx_findapp(const char *app);
* *
* \return 0 on success, and -1 on failure * \return 0 on success, and -1 on failure
*/ */
int pbx_exec(struct ast_channel *c, struct ast_app *app, void *data, int newstack); int pbx_exec(struct ast_channel *c, struct ast_app *app, void *data);
/*! /*!
* \brief Register a new context * \brief Register a new context
@ -486,22 +483,6 @@ int ast_extension_close(const char *pattern, const char *data, int needmore);
int ast_spawn_extension(struct ast_channel *c, const char *context, 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);
/*!
* \brief Execute an extension.
*
* \param c channel to execute upon
* \param context which context extension is in
* \param exten extension to execute
* \param priority priority to execute within the given extension
* \param callerid Caller-ID
*
* If it's not available, do whatever you should do for
* default extensions and halt the thread if necessary. This function does not
* return, except on error.
*/
int ast_exec_extension(struct ast_channel *c, const char *context,
const char *exten, int priority, const char *callerid);
/*! /*!
* \brief Add a context include * \brief Add a context include
* *

62
pbx.c

@ -478,34 +478,29 @@ struct ast_state_cb *statecbs = NULL;
how many times it is called, it returns to the same place */ how many times it is called, it returns to the same place */
int pbx_exec(struct ast_channel *c, /*!< Channel */ int pbx_exec(struct ast_channel *c, /*!< Channel */
struct ast_app *app, /*!< Application */ struct ast_app *app, /*!< Application */
void *data, /*!< Data for execution */ void *data) /*!< Data for execution */
int newstack) /*!< Force stack increment */
{ {
int res; int res;
char *saved_c_appl; const char *saved_c_appl;
char *saved_c_data; const char *saved_c_data;
int (*execute)(struct ast_channel *chan, void *data) = app->execute; int (*execute)(struct ast_channel *chan, void *data) = app->execute;
if (newstack) { if (c->cdr)
if (c->cdr) ast_cdr_setapp(c->cdr, app->name, data);
ast_cdr_setapp(c->cdr, app->name, data);
/* save channel values */ /* save channel values */
saved_c_appl= c->appl; saved_c_appl= c->appl;
saved_c_data= c->data; saved_c_data= c->data;
c->appl = app->name; c->appl = app->name;
c->data = data; c->data = data;
res = execute(c, data); res = execute(c, data);
/* restore channel values */ /* restore channel values */
c->appl= saved_c_appl; c->appl= saved_c_appl;
c->data= saved_c_data; c->data= saved_c_data;
return res; return res;
} else
ast_log(LOG_WARNING, "You really didn't want to call this function with newstack set to 0\n");
return -1;
} }
@ -514,7 +509,6 @@ int pbx_exec(struct ast_channel *c, /*!< Channel */
#define HELPER_EXISTS 0 #define HELPER_EXISTS 0
#define HELPER_SPAWN 1 #define HELPER_SPAWN 1
#define HELPER_EXEC 2
#define HELPER_CANMATCH 3 #define HELPER_CANMATCH 3
#define HELPER_MATCHMORE 4 #define HELPER_MATCHMORE 4
#define HELPER_FINDLABEL 5 #define HELPER_FINDLABEL 5
@ -1500,7 +1494,6 @@ static int pbx_extension_helper(struct ast_channel *c, struct ast_context *con,
struct ast_switch *sw; struct ast_switch *sw;
char *data; char *data;
const char *foundcontext=NULL; const char *foundcontext=NULL;
int newstack = 0;
int res; int res;
int status = 0; int status = 0;
char *incstack[AST_PBX_MAX_STACK]; char *incstack[AST_PBX_MAX_STACK];
@ -1536,9 +1529,6 @@ static int pbx_extension_helper(struct ast_channel *c, struct ast_context *con,
ast_mutex_unlock(&conlock); ast_mutex_unlock(&conlock);
return -1; return -1;
case HELPER_SPAWN: case HELPER_SPAWN:
newstack++;
/* Fall through */
case HELPER_EXEC:
app = pbx_findapp(e->app); app = pbx_findapp(e->app);
ast_mutex_unlock(&conlock); ast_mutex_unlock(&conlock);
if (app) { if (app) {
@ -1551,7 +1541,7 @@ static int pbx_extension_helper(struct ast_channel *c, struct ast_context *con,
if (option_debug) { if (option_debug) {
ast_log(LOG_DEBUG, "Launching '%s'\n", app->name); ast_log(LOG_DEBUG, "Launching '%s'\n", app->name);
snprintf(atmp, 80, "STACK-%s-%s-%d", context, exten, priority); snprintf(atmp, 80, "STACK-%s-%s-%d", context, exten, priority);
snprintf(atmp2, EXT_DATA_SIZE+100, "%s(\"%s\", \"%s\") %s", app->name, c->name, passdata, (newstack ? "in new stack" : "in same stack")); snprintf(atmp2, EXT_DATA_SIZE+100, "%s(\"%s\", \"%s\") %s", app->name, c->name, passdata, "in new stack");
pbx_builtin_setvar_helper(c, atmp, atmp2); pbx_builtin_setvar_helper(c, atmp, atmp2);
} }
if (option_verbose > 2) if (option_verbose > 2)
@ -1559,7 +1549,7 @@ static int pbx_extension_helper(struct ast_channel *c, struct ast_context *con,
term_color(tmp, app->name, COLOR_BRCYAN, 0, sizeof(tmp)), term_color(tmp, app->name, COLOR_BRCYAN, 0, sizeof(tmp)),
term_color(tmp2, c->name, COLOR_BRMAGENTA, 0, sizeof(tmp2)), term_color(tmp2, c->name, COLOR_BRMAGENTA, 0, sizeof(tmp2)),
term_color(tmp3, passdata, COLOR_BRMAGENTA, 0, sizeof(tmp3)), term_color(tmp3, passdata, COLOR_BRMAGENTA, 0, sizeof(tmp3)),
(newstack ? "in new stack" : "in same stack")); "in new stack");
manager_event(EVENT_FLAG_CALL, "Newexten", manager_event(EVENT_FLAG_CALL, "Newexten",
"Channel: %s\r\n" "Channel: %s\r\n"
"Context: %s\r\n" "Context: %s\r\n"
@ -1569,7 +1559,7 @@ static int pbx_extension_helper(struct ast_channel *c, struct ast_context *con,
"AppData: %s\r\n" "AppData: %s\r\n"
"Uniqueid: %s\r\n", "Uniqueid: %s\r\n",
c->name, c->context, c->exten, c->priority, app->name, passdata, c->uniqueid); c->name, c->context, c->exten, c->priority, app->name, passdata, c->uniqueid);
res = pbx_exec(c, app, passdata, newstack); res = pbx_exec(c, app, passdata);
return res; return res;
} else { } else {
ast_log(LOG_WARNING, "No application '%s' for extension (%s, %s, %d)\n", e->app, context, exten, priority); ast_log(LOG_WARNING, "No application '%s' for extension (%s, %s, %d)\n", e->app, context, exten, priority);
@ -1594,12 +1584,9 @@ static int pbx_extension_helper(struct ast_channel *c, struct ast_context *con,
ast_mutex_unlock(&conlock); ast_mutex_unlock(&conlock);
return -1; return -1;
case HELPER_SPAWN: case HELPER_SPAWN:
newstack++;
/* Fall through */
case HELPER_EXEC:
ast_mutex_unlock(&conlock); ast_mutex_unlock(&conlock);
if (sw->exec) if (sw->exec)
res = sw->exec(c, foundcontext ? foundcontext : context, exten, priority, callerid, newstack, data); res = sw->exec(c, foundcontext ? foundcontext : context, exten, priority, callerid, data);
else { else {
ast_log(LOG_WARNING, "No execution engine for switch %s\n", sw->name); ast_log(LOG_WARNING, "No execution engine for switch %s\n", sw->name);
res = -1; res = -1;
@ -2075,11 +2062,6 @@ int ast_spawn_extension(struct ast_channel *c, const char *context, const char *
return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, HELPER_SPAWN); return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, HELPER_SPAWN);
} }
int ast_exec_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, HELPER_EXEC);
}
static int __ast_pbx_run(struct ast_channel *c) static int __ast_pbx_run(struct ast_channel *c)
{ {
int firstpass = 1; int firstpass = 1;
@ -4600,7 +4582,7 @@ static void *async_wait(void *data)
if (app) { if (app) {
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Launching %s(%s) on %s\n", as->app, as->appdata, chan->name); ast_verbose(VERBOSE_PREFIX_3 "Launching %s(%s) on %s\n", as->app, as->appdata, chan->name);
pbx_exec(chan, app, as->appdata, 1); pbx_exec(chan, app, as->appdata);
} else } else
ast_log(LOG_WARNING, "No such application '%s'\n", as->app); ast_log(LOG_WARNING, "No such application '%s'\n", as->app);
} else { } else {
@ -4814,7 +4796,7 @@ static void *ast_pbx_run_app(void *data)
if (app) { if (app) {
if (option_verbose > 3) if (option_verbose > 3)
ast_verbose(VERBOSE_PREFIX_4 "Launching %s(%s) on %s\n", tmp->app, tmp->data, tmp->chan->name); ast_verbose(VERBOSE_PREFIX_4 "Launching %s(%s) on %s\n", tmp->app, tmp->data, tmp->chan->name);
pbx_exec(tmp->chan, app, tmp->data, 1); pbx_exec(tmp->chan, app, tmp->data);
} else } else
ast_log(LOG_WARNING, "No such application '%s'\n", tmp->app); ast_log(LOG_WARNING, "No such application '%s'\n", tmp->app);
ast_hangup(tmp->chan); ast_hangup(tmp->chan);
@ -5247,7 +5229,7 @@ static int pbx_builtin_execiftime(struct ast_channel *chan, void *data)
} }
if ((app = pbx_findapp(ptr2))) { if ((app = pbx_findapp(ptr2))) {
res = pbx_exec(chan, app, ptr1 ? ptr1 : "", 1); res = pbx_exec(chan, app, ptr1 ? ptr1 : "");
} else { } else {
ast_log(LOG_WARNING, "Cannot locate application %s\n", ptr2); ast_log(LOG_WARNING, "Cannot locate application %s\n", ptr2);
res = -1; res = -1;

@ -4382,7 +4382,7 @@ static int dundi_canmatch(struct ast_channel *chan, const char *context, const c
return dundi_helper(chan, context, exten, priority, data, DUNDI_FLAG_CANMATCH); return dundi_helper(chan, context, exten, priority, data, DUNDI_FLAG_CANMATCH);
} }
static int dundi_exec(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, int newstack, const char *data) static int dundi_exec(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
{ {
struct dundi_result results[MAX_RESULTS]; struct dundi_result results[MAX_RESULTS];
int res; int res;
@ -4428,7 +4428,7 @@ static int dundi_exec(struct ast_channel *chan, const char *context, const char
snprintf(req, sizeof(req), "%s/%s", results[x].tech, results[x].dest); snprintf(req, sizeof(req), "%s/%s", results[x].tech, results[x].dest);
dial = pbx_findapp("Dial"); dial = pbx_findapp("Dial");
if (dial) if (dial)
res = pbx_exec(chan, dial, req, newstack); res = pbx_exec(chan, dial, req);
} else } else
res = -1; res = -1;
return res; return res;

@ -147,13 +147,11 @@ static int loopback_canmatch(struct ast_channel *chan, const char *context, cons
return res; return res;
} }
static int loopback_exec(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, int newstack, const char *data) static int loopback_exec(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
{ {
LOOPBACK_COMMON; LOOPBACK_COMMON;
if (newstack) res = ast_spawn_extension(chan, newcontext, newexten, newpriority, callerid);
res = ast_spawn_extension(chan, newcontext, newexten, newpriority, callerid); /* XXX hmmm... res is overridden ? */
else
res = ast_exec_extension(chan, newcontext, newexten, newpriority, callerid);
if (newpattern && !ast_extension_match(newpattern, exten)) if (newpattern && !ast_extension_match(newpattern, exten))
res = -1; res = -1;
return res; return res;

@ -177,14 +177,14 @@ static int realtime_canmatch(struct ast_channel *chan, const char *context, cons
return res > 0 ? res : 0; return res > 0 ? res : 0;
} }
static int realtime_exec(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, int newstack, const char *data) static int realtime_exec(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
{ {
char app[256]; char app[256];
char appdata[512]=""; char appdata[512]="";
char *tmp=""; char *tmp="";
char tmp1[80]; char tmp1[80];
char tmp2[80]; char tmp2[80];
char tmp3[EXT_DATA_SIZE]; char tmp3[EXT_DATA_SIZE];
struct ast_app *a; struct ast_app *a;
struct ast_variable *v; struct ast_variable *v;
REALTIME_COMMON(MODE_MATCH); REALTIME_COMMON(MODE_MATCH);
@ -218,7 +218,7 @@ static int realtime_exec(struct ast_channel *chan, const char *context, const ch
"Uniqueid: %s\r\n", "Uniqueid: %s\r\n",
chan->name, chan->context, chan->exten, chan->priority, app, appdata ? appdata : "(NULL)", chan->uniqueid); chan->name, chan->context, chan->exten, chan->priority, app, appdata ? appdata : "(NULL)", chan->uniqueid);
res = pbx_exec(chan, a, appdata, newstack); res = pbx_exec(chan, a, appdata);
} else } else
ast_log(LOG_NOTICE, "No such application '%s' for extension '%s' in context '%s'\n", app, exten, context); ast_log(LOG_NOTICE, "No such application '%s' for extension '%s' in context '%s'\n", app, exten, context);
} }

@ -1090,7 +1090,7 @@ static int handle_exec(struct ast_channel *chan, AGI *agi, int argc, char **argv
app = pbx_findapp(argv[1]); app = pbx_findapp(argv[1]);
if (app) { if (app) {
res = pbx_exec(chan, app, argv[2], 1); res = pbx_exec(chan, app, argv[2]);
} else { } else {
ast_log(LOG_WARNING, "Could not find application (%s)\n", argv[1]); ast_log(LOG_WARNING, "Could not find application (%s)\n", argv[1]);
res = -2; res = -2;

@ -502,7 +502,7 @@ static int builtin_automonitor(struct ast_channel *chan, struct ast_channel *pee
if (option_verbose > 3) if (option_verbose > 3)
ast_verbose(VERBOSE_PREFIX_3 "User hit '%s' to record call. filename: %s\n", code, args); ast_verbose(VERBOSE_PREFIX_3 "User hit '%s' to record call. filename: %s\n", code, args);
pbx_exec(callee_chan, monitor_app, args, 1); pbx_exec(callee_chan, monitor_app, args);
pbx_builtin_setvar_helper(callee_chan, "TOUCH_MONITOR_OUTPUT", touch_filename); pbx_builtin_setvar_helper(callee_chan, "TOUCH_MONITOR_OUTPUT", touch_filename);
pbx_builtin_setvar_helper(caller_chan, "TOUCH_MONITOR_OUTPUT", touch_filename); pbx_builtin_setvar_helper(caller_chan, "TOUCH_MONITOR_OUTPUT", touch_filename);
@ -924,7 +924,7 @@ static int feature_exec_app(struct ast_channel *chan, struct ast_channel *peer,
struct ast_channel *work = chan; struct ast_channel *work = chan;
if (ast_test_flag(feature, AST_FEATURE_FLAG_CALLEE)) if (ast_test_flag(feature, AST_FEATURE_FLAG_CALLEE))
work = peer; work = peer;
res = pbx_exec(work, app, feature->app_args, 1); res = pbx_exec(work, app, feature->app_args);
if (res < 0) if (res < 0)
return res; return res;
} else { } else {
@ -1267,7 +1267,7 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast
if (monitor_app && src) { if (monitor_app && src) {
char *tmp = ast_strdupa(monitor_exec); char *tmp = ast_strdupa(monitor_exec);
if (tmp) { if (tmp) {
pbx_exec(src, monitor_app, tmp, 1); pbx_exec(src, monitor_app, tmp);
} else { } else {
ast_log(LOG_ERROR, "Monitor failed: out of memory\n"); ast_log(LOG_ERROR, "Monitor failed: out of memory\n");
} }

Loading…
Cancel
Save