From 6c232811c0bf80366955a6bcfb0f7619c4d65717 Mon Sep 17 00:00:00 2001 From: Luigi Rizzo <rizzo@icir.org> Date: Thu, 30 Mar 2006 21:29:39 +0000 Subject: [PATCH] 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 --- apps/app_dial.c | 2 +- apps/app_exec.c | 2 +- apps/app_meetme.c | 2 +- apps/app_page.c | 2 +- apps/app_voicemail.c | 2 +- apps/app_while.c | 2 +- channels/chan_iax2.c | 6 ++-- include/asterisk/channel.h | 6 ++-- include/asterisk/pbx.h | 41 +++++++------------------ pbx.c | 62 ++++++++++++++------------------------ pbx/pbx_dundi.c | 4 +-- pbx/pbx_loopback.c | 8 ++--- pbx/pbx_realtime.c | 10 +++--- res/res_agi.c | 2 +- res/res_features.c | 6 ++-- 15 files changed, 58 insertions(+), 99 deletions(-) diff --git a/apps/app_dial.c b/apps/app_dial.c index 2f9a4b0a3e..921ee46a0d 100644 --- a/apps/app_dial.c +++ b/apps/app_dial.c @@ -1449,7 +1449,7 @@ static int dial_exec_full(struct ast_channel *chan, void *data, struct ast_flags if (*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); res = 0; } else { diff --git a/apps/app_exec.c b/apps/app_exec.c index 3b1f30a4f3..2acd1b3d65 100644 --- a/apps/app_exec.c +++ b/apps/app_exec.c @@ -82,7 +82,7 @@ static int exec_exec(struct ast_channel *chan, void *data) if (appname) { app = pbx_findapp(appname); if (app) { - res = pbx_exec(chan, app, args, 1); + res = pbx_exec(chan, app, args); } else { ast_log(LOG_WARNING, "Could not find application (%s)\n", appname); res = -1; diff --git a/apps/app_meetme.c b/apps/app_meetme.c index f1e213885b..2229c57da4 100644 --- a/apps/app_meetme.c +++ b/apps/app_meetme.c @@ -1143,7 +1143,7 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int c app = pbx_findapp("agi"); if (app) { char *s = ast_strdupa(agifile); - ret = pbx_exec(chan, app, s, 1); + ret = pbx_exec(chan, app, s); } else { ast_log(LOG_WARNING, "Could not find application (agi)\n"); ret = -2; diff --git a/apps/app_page.c b/apps/app_page.c index d848fb875d..a9ad2c16d8 100644 --- a/apps/app_page.c +++ b/apps/app_page.c @@ -186,7 +186,7 @@ static int page_exec(struct ast_channel *chan, void *data) } if (!res) { 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); diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index c0abc2a4d4..3690083901 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -3422,7 +3422,7 @@ static int forward_message(struct ast_channel *chan, char *context, char *dir, i old_priority = chan->priority; /* 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)); diff --git a/apps/app_while.c b/apps/app_while.c index 423858a8e1..8805e60b51 100644 --- a/apps/app_while.c +++ b/apps/app_while.c @@ -101,7 +101,7 @@ static int execif_exec(struct ast_channel *chan, void *data) { if (ast_true(expr)) { if ((app = pbx_findapp(myapp))) { - res = pbx_exec(chan, app, mydata, 1); + res = pbx_exec(chan, app, mydata); } else { ast_log(LOG_WARNING, "Count not find application! (%s)\n", myapp); res = -1; diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index 0d77cb9189..67bfdea571 100644 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -9573,7 +9573,7 @@ static int iax2_matchmore(struct ast_channel *chan, const char *context, const c } /*! \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 req[256]; @@ -9589,7 +9589,7 @@ static int iax2_exec(struct ast_channel *chan, const char *context, const char * if (dialstatus) { dial = pbx_findapp(dialstatus); if (dial) - pbx_exec(chan, dial, "", newstack); + pbx_exec(chan, dial, ""); } return -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); dial = pbx_findapp("Dial"); if (dial) { - return pbx_exec(chan, dial, req, newstack); + return pbx_exec(chan, dial, req); } else { ast_log(LOG_WARNING, "No dial application registered\n"); } diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h index 9cdc280ac7..9fcc4b1338 100644 --- a/include/asterisk/channel.h +++ b/include/asterisk/channel.h @@ -317,10 +317,8 @@ struct ast_channel { /*! Procedure causing blocking */ const char *blockproc; - /*! Current application */ - char *appl; - /*! Data passed to current application */ - char *data; + const char *appl; /*! Current application */ + const char *data; /*! Data passed to current application */ /*! Which fd had an event detected on */ int fdno; diff --git a/include/asterisk/pbx.h b/include/asterisk/pbx.h index 8c18fcc03c..deaa578bfe 100644 --- a/include/asterisk/pbx.h +++ b/include/asterisk/pbx.h @@ -82,22 +82,20 @@ struct ast_custom_function { 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 */ struct ast_switch { - /*! NULL */ struct ast_switch *next; - /*! Name of the switch */ - const char *name; - /*! 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); + const char *name; /*! Name of the switch */ + const char *description; /*! Description of the switch */ - int (*exec)(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, int newstack, const char *data); - - int (*matchmore)(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data); + ast_switch_f *exists; + ast_switch_f *canmatch; + ast_switch_f *exec; + ast_switch_f *matchmore; }; struct ast_timing { @@ -160,7 +158,6 @@ struct ast_app *pbx_findapp(const char *app); * \param c channel to execute on * \param app which app to execute * \param data the data passed into the app - * \param newstack stack pointer * * This application executes an application on a given channel. It * 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 */ -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 @@ -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, 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 * diff --git a/pbx.c b/pbx.c index 1ee2c90290..822155187f 100644 --- a/pbx.c +++ b/pbx.c @@ -478,34 +478,29 @@ struct ast_state_cb *statecbs = NULL; how many times it is called, it returns to the same place */ int pbx_exec(struct ast_channel *c, /*!< Channel */ struct ast_app *app, /*!< Application */ - void *data, /*!< Data for execution */ - int newstack) /*!< Force stack increment */ + void *data) /*!< Data for execution */ { int res; - char *saved_c_appl; - char *saved_c_data; + const char *saved_c_appl; + const char *saved_c_data; int (*execute)(struct ast_channel *chan, void *data) = app->execute; - if (newstack) { - if (c->cdr) - ast_cdr_setapp(c->cdr, app->name, data); + if (c->cdr) + ast_cdr_setapp(c->cdr, app->name, data); - /* save channel values */ - saved_c_appl= c->appl; - saved_c_data= c->data; + /* save channel values */ + saved_c_appl= c->appl; + saved_c_data= c->data; - c->appl = app->name; - c->data = data; - res = execute(c, data); - /* restore channel values */ - c->appl= saved_c_appl; - c->data= saved_c_data; - return res; - } else - ast_log(LOG_WARNING, "You really didn't want to call this function with newstack set to 0\n"); - return -1; + c->appl = app->name; + c->data = data; + res = execute(c, data); + /* restore channel values */ + c->appl= saved_c_appl; + c->data= saved_c_data; + return res; } @@ -514,7 +509,6 @@ int pbx_exec(struct ast_channel *c, /*!< Channel */ #define HELPER_EXISTS 0 #define HELPER_SPAWN 1 -#define HELPER_EXEC 2 #define HELPER_CANMATCH 3 #define HELPER_MATCHMORE 4 #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; char *data; const char *foundcontext=NULL; - int newstack = 0; int res; int status = 0; 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); return -1; case HELPER_SPAWN: - newstack++; - /* Fall through */ - case HELPER_EXEC: app = pbx_findapp(e->app); ast_mutex_unlock(&conlock); if (app) { @@ -1551,7 +1541,7 @@ static int pbx_extension_helper(struct ast_channel *c, struct ast_context *con, if (option_debug) { ast_log(LOG_DEBUG, "Launching '%s'\n", app->name); 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); } 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(tmp2, c->name, COLOR_BRMAGENTA, 0, sizeof(tmp2)), 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", "Channel: %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" "Uniqueid: %s\r\n", 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; } else { 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); return -1; case HELPER_SPAWN: - newstack++; - /* Fall through */ - case HELPER_EXEC: ast_mutex_unlock(&conlock); 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 { ast_log(LOG_WARNING, "No execution engine for switch %s\n", sw->name); 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); } -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) { int firstpass = 1; @@ -4600,7 +4582,7 @@ static void *async_wait(void *data) if (app) { if (option_verbose > 2) 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 ast_log(LOG_WARNING, "No such application '%s'\n", as->app); } else { @@ -4814,7 +4796,7 @@ static void *ast_pbx_run_app(void *data) if (app) { if (option_verbose > 3) 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 ast_log(LOG_WARNING, "No such application '%s'\n", tmp->app); ast_hangup(tmp->chan); @@ -5247,7 +5229,7 @@ static int pbx_builtin_execiftime(struct ast_channel *chan, void *data) } if ((app = pbx_findapp(ptr2))) { - res = pbx_exec(chan, app, ptr1 ? ptr1 : "", 1); + res = pbx_exec(chan, app, ptr1 ? ptr1 : ""); } else { ast_log(LOG_WARNING, "Cannot locate application %s\n", ptr2); res = -1; diff --git a/pbx/pbx_dundi.c b/pbx/pbx_dundi.c index 2e257d8aea..e81753213d 100644 --- a/pbx/pbx_dundi.c +++ b/pbx/pbx_dundi.c @@ -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); } -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]; 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); dial = pbx_findapp("Dial"); if (dial) - res = pbx_exec(chan, dial, req, newstack); + res = pbx_exec(chan, dial, req); } else res = -1; return res; diff --git a/pbx/pbx_loopback.c b/pbx/pbx_loopback.c index 5522e9b092..ffa006527f 100644 --- a/pbx/pbx_loopback.c +++ b/pbx/pbx_loopback.c @@ -147,13 +147,11 @@ static int loopback_canmatch(struct ast_channel *chan, const char *context, cons 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; - if (newstack) - res = ast_spawn_extension(chan, newcontext, newexten, newpriority, callerid); - else - res = ast_exec_extension(chan, newcontext, newexten, newpriority, callerid); + res = ast_spawn_extension(chan, newcontext, newexten, newpriority, callerid); + /* XXX hmmm... res is overridden ? */ if (newpattern && !ast_extension_match(newpattern, exten)) res = -1; return res; diff --git a/pbx/pbx_realtime.c b/pbx/pbx_realtime.c index 4e9aba1fe0..bd9be8c568 100644 --- a/pbx/pbx_realtime.c +++ b/pbx/pbx_realtime.c @@ -177,14 +177,14 @@ static int realtime_canmatch(struct ast_channel *chan, const char *context, cons 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 appdata[512]=""; char *tmp=""; - char tmp1[80]; - char tmp2[80]; - char tmp3[EXT_DATA_SIZE]; + char tmp1[80]; + char tmp2[80]; + char tmp3[EXT_DATA_SIZE]; struct ast_app *a; struct ast_variable *v; 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", 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 ast_log(LOG_NOTICE, "No such application '%s' for extension '%s' in context '%s'\n", app, exten, context); } diff --git a/res/res_agi.c b/res/res_agi.c index 2a6849a688..e88920da37 100644 --- a/res/res_agi.c +++ b/res/res_agi.c @@ -1090,7 +1090,7 @@ static int handle_exec(struct ast_channel *chan, AGI *agi, int argc, char **argv app = pbx_findapp(argv[1]); if (app) { - res = pbx_exec(chan, app, argv[2], 1); + res = pbx_exec(chan, app, argv[2]); } else { ast_log(LOG_WARNING, "Could not find application (%s)\n", argv[1]); res = -2; diff --git a/res/res_features.c b/res/res_features.c index 59d263f518..ebd225f8a8 100644 --- a/res/res_features.c +++ b/res/res_features.c @@ -502,7 +502,7 @@ static int builtin_automonitor(struct ast_channel *chan, struct ast_channel *pee if (option_verbose > 3) 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(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; if (ast_test_flag(feature, AST_FEATURE_FLAG_CALLEE)) work = peer; - res = pbx_exec(work, app, feature->app_args, 1); + res = pbx_exec(work, app, feature->app_args); if (res < 0) return res; } else { @@ -1267,7 +1267,7 @@ int ast_bridge_call(struct ast_channel *chan,struct ast_channel *peer,struct ast if (monitor_app && src) { char *tmp = ast_strdupa(monitor_exec); if (tmp) { - pbx_exec(src, monitor_app, tmp, 1); + pbx_exec(src, monitor_app, tmp); } else { ast_log(LOG_ERROR, "Monitor failed: out of memory\n"); } -- GitLab