Exec application. More...
#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/app.h"
Go to the source code of this file.
Defines | |
#define | MAXRESULT 1024 |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | exec_exec (struct ast_channel *chan, void *data) |
static int | execif_exec (struct ast_channel *chan, void *data) |
static int | load_module (void) |
static int | tryexec_exec (struct ast_channel *chan, void *data) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info __MODULE_INFO_SECTION | __mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Executes dialplan applications" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } |
static char * | app_exec = "Exec" |
static char * | app_execif = "ExecIf" |
static char * | app_tryexec = "TryExec" |
static struct ast_module_info * | ast_module_info = &__mod_info |
Exec application.
Definition in file app_exec.c.
#define MAXRESULT 1024 |
Definition at line 114 of file app_exec.c.
Referenced by exec_exec(), substituted(), and tryexec_exec().
static void __reg_module | ( | void | ) | [static] |
Definition at line 293 of file app_exec.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 293 of file app_exec.c.
static int exec_exec | ( | struct ast_channel * | chan, |
void * | data | ||
) | [static] |
Definition at line 132 of file app_exec.c.
References app, ast_log(), ast_strdupa, ast_strlen_zero(), LOG_WARNING, MAXRESULT, pbx_exec(), pbx_findapp(), pbx_substitute_variables_helper(), s, and strsep().
Referenced by load_module().
{ int res = 0; char *s, *appname, *endargs, args[MAXRESULT]; struct ast_app *app; if (ast_strlen_zero(data)) return 0; s = ast_strdupa(data); args[0] = 0; appname = strsep(&s, "("); if (s) { endargs = strrchr(s, ')'); if (endargs) *endargs = '\0'; pbx_substitute_variables_helper(chan, s, args, MAXRESULT - 1); } if (appname) { app = pbx_findapp(appname); if (app) { res = pbx_exec(chan, app, args); } else { ast_log(LOG_WARNING, "Could not find application (%s)\n", appname); res = -1; } } return res; }
static int execif_exec | ( | struct ast_channel * | chan, |
void * | data | ||
) | [static] |
Definition at line 195 of file app_exec.c.
References app, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), AST_NONSTANDARD_RAW_ARGS, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), f, LOG_ERROR, LOG_WARNING, parse(), pbx_checkcondition(), pbx_exec(), pbx_findapp(), and S_OR.
Referenced by load_module().
{ int res = 0; char *truedata = NULL, *falsedata = NULL, *end, *firstcomma, *firstquestion; struct ast_app *app = NULL; AST_DECLARE_APP_ARGS(expr, AST_APP_ARG(expr); AST_APP_ARG(remainder); ); AST_DECLARE_APP_ARGS(apps, AST_APP_ARG(t); AST_APP_ARG(f); ); char *parse = ast_strdupa(data); firstcomma = strchr(parse, ','); firstquestion = strchr(parse, '?'); if ((firstcomma != NULL && firstquestion != NULL && firstcomma < firstquestion) || (firstquestion == NULL)) { /* Deprecated syntax */ AST_DECLARE_APP_ARGS(depr, AST_APP_ARG(expr); AST_APP_ARG(appname); AST_APP_ARG(appargs); ); AST_STANDARD_APP_ARGS(depr, parse); ast_log(LOG_WARNING, "Deprecated syntax found. Please upgrade to using ExecIf(<expr>?%s(%s))\n", depr.appname, depr.appargs); /* Make the two syntaxes look the same */ expr.expr = depr.expr; apps.t = depr.appname; apps.f = NULL; truedata = depr.appargs; } else { /* Preferred syntax */ AST_NONSTANDARD_RAW_ARGS(expr, parse, '?'); if (ast_strlen_zero(expr.remainder)) { ast_log(LOG_ERROR, "Usage: ExecIf(<expr>?<appiftrue>(<args>)[:<appiffalse>(<args)])\n"); return -1; } AST_NONSTANDARD_RAW_ARGS(apps, expr.remainder, ':'); if (apps.t && (truedata = strchr(apps.t, '('))) { *truedata++ = '\0'; if ((end = strrchr(truedata, ')'))) { *end = '\0'; } } if (apps.f && (falsedata = strchr(apps.f, '('))) { *falsedata++ = '\0'; if ((end = strrchr(falsedata, ')'))) { *end = '\0'; } } } if (pbx_checkcondition(expr.expr)) { if (!ast_strlen_zero(apps.t) && (app = pbx_findapp(apps.t))) { res = pbx_exec(chan, app, S_OR(truedata, "")); } else { ast_log(LOG_WARNING, "Could not find application! (%s)\n", apps.t); res = -1; } } else if (!ast_strlen_zero(apps.f)) { if ((app = pbx_findapp(apps.f))) { res = pbx_exec(chan, app, S_OR(falsedata, "")); } else { ast_log(LOG_WARNING, "Could not find application! (%s)\n", apps.f); res = -1; } } return res; }
static int load_module | ( | void | ) | [static] |
Definition at line 285 of file app_exec.c.
References ast_register_application_xml, exec_exec(), execif_exec(), and tryexec_exec().
{ int res = ast_register_application_xml(app_exec, exec_exec); res |= ast_register_application_xml(app_tryexec, tryexec_exec); res |= ast_register_application_xml(app_execif, execif_exec); return res; }
static int tryexec_exec | ( | struct ast_channel * | chan, |
void * | data | ||
) | [static] |
Definition at line 163 of file app_exec.c.
References app, ast_log(), ast_strdupa, ast_strlen_zero(), LOG_WARNING, MAXRESULT, pbx_builtin_setvar_helper(), pbx_exec(), pbx_findapp(), pbx_substitute_variables_helper(), s, and strsep().
Referenced by load_module().
{ int res = 0; char *s, *appname, *endargs, args[MAXRESULT]; struct ast_app *app; if (ast_strlen_zero(data)) return 0; s = ast_strdupa(data); args[0] = 0; appname = strsep(&s, "("); if (s) { endargs = strrchr(s, ')'); if (endargs) *endargs = '\0'; pbx_substitute_variables_helper(chan, s, args, MAXRESULT - 1); } if (appname) { app = pbx_findapp(appname); if (app) { res = pbx_exec(chan, app, args); pbx_builtin_setvar_helper(chan, "TRYSTATUS", res ? "FAILED" : "SUCCESS"); } else { ast_log(LOG_WARNING, "Could not find application (%s)\n", appname); pbx_builtin_setvar_helper(chan, "TRYSTATUS", "NOAPP"); } } return 0; }
static int unload_module | ( | void | ) | [static] |
Definition at line 274 of file app_exec.c.
References ast_unregister_application().
{ int res; res = ast_unregister_application(app_exec); res |= ast_unregister_application(app_tryexec); res |= ast_unregister_application(app_execif); return res; }
struct ast_module_info __MODULE_INFO_SECTION __mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Executes dialplan applications" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } [static] |
Definition at line 293 of file app_exec.c.
char* app_exec = "Exec" [static] |
Note
The key difference between these two apps is exit status. In a nutshell, Exec tries to be transparent as possible, behaving in exactly the same way as if the application it calls was directly invoked from the dialplan.
TryExec, on the other hand, provides a way to execute applications and catch any possible fatal error without actually fatally affecting the dialplan.
Definition at line 128 of file app_exec.c.
char* app_execif = "ExecIf" [static] |
Definition at line 130 of file app_exec.c.
char* app_tryexec = "TryExec" [static] |
Definition at line 129 of file app_exec.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 293 of file app_exec.c.