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 | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Executes dialplan applications" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "0901e4e500243c855563a2d78b0c03e4" , .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 cut_internal(), 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_strlen_zero(), LOG_WARNING, MAXRESULT, pbx_exec(), pbx_findapp(), pbx_substitute_variables_helper(), and s.
Referenced by load_module().
00133 { 00134 int res = 0; 00135 char *s, *appname, *endargs, args[MAXRESULT]; 00136 struct ast_app *app; 00137 00138 if (ast_strlen_zero(data)) 00139 return 0; 00140 00141 s = ast_strdupa(data); 00142 args[0] = 0; 00143 appname = strsep(&s, "("); 00144 if (s) { 00145 endargs = strrchr(s, ')'); 00146 if (endargs) 00147 *endargs = '\0'; 00148 pbx_substitute_variables_helper(chan, s, args, MAXRESULT - 1); 00149 } 00150 if (appname) { 00151 app = pbx_findapp(appname); 00152 if (app) { 00153 res = pbx_exec(chan, app, args); 00154 } else { 00155 ast_log(LOG_WARNING, "Could not find application (%s)\n", appname); 00156 res = -1; 00157 } 00158 } 00159 00160 return res; 00161 }
| 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_APP_ARGS, AST_STANDARD_APP_ARGS, ast_strlen_zero(), f, LOG_ERROR, LOG_WARNING, parse(), pbx_checkcondition(), pbx_exec(), pbx_findapp(), and S_OR.
Referenced by load_module().
00196 { 00197 int res = 0; 00198 char *truedata = NULL, *falsedata = NULL, *end, *firstcomma, *firstquestion; 00199 struct ast_app *app = NULL; 00200 AST_DECLARE_APP_ARGS(expr, 00201 AST_APP_ARG(expr); 00202 AST_APP_ARG(remainder); 00203 ); 00204 AST_DECLARE_APP_ARGS(apps, 00205 AST_APP_ARG(t); 00206 AST_APP_ARG(f); 00207 ); 00208 char *parse = ast_strdupa(data); 00209 00210 firstcomma = strchr(parse, ','); 00211 firstquestion = strchr(parse, '?'); 00212 00213 if ((firstcomma != NULL && firstquestion != NULL && firstcomma < firstquestion) || (firstquestion == NULL)) { 00214 /* Deprecated syntax */ 00215 AST_DECLARE_APP_ARGS(depr, 00216 AST_APP_ARG(expr); 00217 AST_APP_ARG(appname); 00218 AST_APP_ARG(appargs); 00219 ); 00220 AST_STANDARD_APP_ARGS(depr, parse); 00221 00222 ast_log(LOG_WARNING, "Deprecated syntax found. Please upgrade to using ExecIf(<expr>?%s(%s))\n", depr.appname, depr.appargs); 00223 00224 /* Make the two syntaxes look the same */ 00225 expr.expr = depr.expr; 00226 apps.t = depr.appname; 00227 apps.f = NULL; 00228 truedata = depr.appargs; 00229 } else { 00230 /* Preferred syntax */ 00231 00232 AST_NONSTANDARD_APP_ARGS(expr, parse, '?'); 00233 if (ast_strlen_zero(expr.remainder)) { 00234 ast_log(LOG_ERROR, "Usage: ExecIf(<expr>?<appiftrue>(<args>)[:<appiffalse>(<args)])\n"); 00235 return -1; 00236 } 00237 00238 AST_NONSTANDARD_APP_ARGS(apps, expr.remainder, ':'); 00239 00240 if (apps.t && (truedata = strchr(apps.t, '('))) { 00241 *truedata++ = '\0'; 00242 if ((end = strrchr(truedata, ')'))) { 00243 *end = '\0'; 00244 } 00245 } 00246 00247 if (apps.f && (falsedata = strchr(apps.f, '('))) { 00248 *falsedata++ = '\0'; 00249 if ((end = strrchr(falsedata, ')'))) { 00250 *end = '\0'; 00251 } 00252 } 00253 } 00254 00255 if (pbx_checkcondition(expr.expr)) { 00256 if (!ast_strlen_zero(apps.t) && (app = pbx_findapp(apps.t))) { 00257 res = pbx_exec(chan, app, S_OR(truedata, "")); 00258 } else { 00259 ast_log(LOG_WARNING, "Could not find application! (%s)\n", apps.t); 00260 res = -1; 00261 } 00262 } else if (!ast_strlen_zero(apps.f)) { 00263 if ((app = pbx_findapp(apps.f))) { 00264 res = pbx_exec(chan, app, S_OR(falsedata, "")); 00265 } else { 00266 ast_log(LOG_WARNING, "Could not find application! (%s)\n", apps.f); 00267 res = -1; 00268 } 00269 } 00270 00271 return res; 00272 }
| 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().
00286 { 00287 int res = ast_register_application_xml(app_exec, exec_exec); 00288 res |= ast_register_application_xml(app_tryexec, tryexec_exec); 00289 res |= ast_register_application_xml(app_execif, execif_exec); 00290 return res; 00291 }
| 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_strlen_zero(), LOG_WARNING, MAXRESULT, pbx_builtin_setvar_helper(), pbx_exec(), pbx_findapp(), pbx_substitute_variables_helper(), and s.
Referenced by load_module().
00164 { 00165 int res = 0; 00166 char *s, *appname, *endargs, args[MAXRESULT]; 00167 struct ast_app *app; 00168 00169 if (ast_strlen_zero(data)) 00170 return 0; 00171 00172 s = ast_strdupa(data); 00173 args[0] = 0; 00174 appname = strsep(&s, "("); 00175 if (s) { 00176 endargs = strrchr(s, ')'); 00177 if (endargs) 00178 *endargs = '\0'; 00179 pbx_substitute_variables_helper(chan, s, args, MAXRESULT - 1); 00180 } 00181 if (appname) { 00182 app = pbx_findapp(appname); 00183 if (app) { 00184 res = pbx_exec(chan, app, args); 00185 pbx_builtin_setvar_helper(chan, "TRYSTATUS", res ? "FAILED" : "SUCCESS"); 00186 } else { 00187 ast_log(LOG_WARNING, "Could not find application (%s)\n", appname); 00188 pbx_builtin_setvar_helper(chan, "TRYSTATUS", "NOAPP"); 00189 } 00190 } 00191 00192 return 0; 00193 }
| static int unload_module | ( | void | ) | [static] |
Definition at line 274 of file app_exec.c.
References ast_unregister_application().
00275 { 00276 int res; 00277 00278 res = ast_unregister_application(app_exec); 00279 res |= ast_unregister_application(app_tryexec); 00280 res |= ast_unregister_application(app_execif); 00281 00282 return res; 00283 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Executes dialplan applications" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "0901e4e500243c855563a2d78b0c03e4" , .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.
1.6.2