#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, const char *data) |
static int | execif_exec (struct ast_channel *chan, const char *data) |
static int | load_module (void) |
static int | tryexec_exec (struct ast_channel *chan, const char *data) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } |
static const char | app_exec [] = "Exec" |
static const char | app_execif [] = "ExecIf" |
static const char | app_tryexec [] = "TryExec" |
static struct ast_module_info * | ast_module_info = &__mod_info |
Philipp Dunkel <philipp.dunkel@ebox.at>
Definition in file app_exec.c.
#define MAXRESULT 1024 |
static void __reg_module | ( | void | ) | [static] |
Definition at line 299 of file app_exec.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 299 of file app_exec.c.
static int exec_exec | ( | struct ast_channel * | chan, | |
const char * | data | |||
) | [static] |
Definition at line 132 of file app_exec.c.
References app, args, ast_free, ast_log(), ast_str_buffer(), ast_str_create(), ast_str_substitute_variables(), ast_strdupa, ast_strlen_zero(), LOG_WARNING, pbx_exec(), pbx_findapp(), and strsep().
Referenced by load_module().
00133 { 00134 int res = 0; 00135 char *s, *appname, *endargs; 00136 struct ast_app *app; 00137 struct ast_str *args = NULL; 00138 00139 if (ast_strlen_zero(data)) 00140 return 0; 00141 00142 s = ast_strdupa(data); 00143 appname = strsep(&s, "("); 00144 if (s) { 00145 endargs = strrchr(s, ')'); 00146 if (endargs) 00147 *endargs = '\0'; 00148 if ((args = ast_str_create(16))) { 00149 ast_str_substitute_variables(&args, 0, chan, s); 00150 } 00151 } 00152 if (appname) { 00153 app = pbx_findapp(appname); 00154 if (app) { 00155 res = pbx_exec(chan, app, args ? ast_str_buffer(args) : NULL); 00156 } else { 00157 ast_log(LOG_WARNING, "Could not find application (%s)\n", appname); 00158 res = -1; 00159 } 00160 } 00161 00162 ast_free(args); 00163 return res; 00164 }
static int execif_exec | ( | struct ast_channel * | chan, | |
const char * | data | |||
) | [static] |
Definition at line 201 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().
00202 { 00203 int res = 0; 00204 char *truedata = NULL, *falsedata = NULL, *end, *firstcomma, *firstquestion; 00205 struct ast_app *app = NULL; 00206 AST_DECLARE_APP_ARGS(expr, 00207 AST_APP_ARG(expr); 00208 AST_APP_ARG(remainder); 00209 ); 00210 AST_DECLARE_APP_ARGS(apps, 00211 AST_APP_ARG(t); 00212 AST_APP_ARG(f); 00213 ); 00214 char *parse = ast_strdupa(data); 00215 00216 firstcomma = strchr(parse, ','); 00217 firstquestion = strchr(parse, '?'); 00218 00219 if ((firstcomma != NULL && firstquestion != NULL && firstcomma < firstquestion) || (firstquestion == NULL)) { 00220 /* Deprecated syntax */ 00221 AST_DECLARE_APP_ARGS(depr, 00222 AST_APP_ARG(expr); 00223 AST_APP_ARG(appname); 00224 AST_APP_ARG(appargs); 00225 ); 00226 AST_STANDARD_APP_ARGS(depr, parse); 00227 00228 ast_log(LOG_WARNING, "Deprecated syntax found. Please upgrade to using ExecIf(<expr>?%s(%s))\n", depr.appname, depr.appargs); 00229 00230 /* Make the two syntaxes look the same */ 00231 expr.expr = depr.expr; 00232 apps.t = depr.appname; 00233 apps.f = NULL; 00234 truedata = depr.appargs; 00235 } else { 00236 /* Preferred syntax */ 00237 00238 AST_NONSTANDARD_RAW_ARGS(expr, parse, '?'); 00239 if (ast_strlen_zero(expr.remainder)) { 00240 ast_log(LOG_ERROR, "Usage: ExecIf(<expr>?<appiftrue>(<args>)[:<appiffalse>(<args)])\n"); 00241 return -1; 00242 } 00243 00244 AST_NONSTANDARD_RAW_ARGS(apps, expr.remainder, ':'); 00245 00246 if (apps.t && (truedata = strchr(apps.t, '('))) { 00247 *truedata++ = '\0'; 00248 if ((end = strrchr(truedata, ')'))) { 00249 *end = '\0'; 00250 } 00251 } 00252 00253 if (apps.f && (falsedata = strchr(apps.f, '('))) { 00254 *falsedata++ = '\0'; 00255 if ((end = strrchr(falsedata, ')'))) { 00256 *end = '\0'; 00257 } 00258 } 00259 } 00260 00261 if (pbx_checkcondition(expr.expr)) { 00262 if (!ast_strlen_zero(apps.t) && (app = pbx_findapp(apps.t))) { 00263 res = pbx_exec(chan, app, S_OR(truedata, "")); 00264 } else { 00265 ast_log(LOG_WARNING, "Could not find application! (%s)\n", apps.t); 00266 res = -1; 00267 } 00268 } else if (!ast_strlen_zero(apps.f)) { 00269 if ((app = pbx_findapp(apps.f))) { 00270 res = pbx_exec(chan, app, S_OR(falsedata, "")); 00271 } else { 00272 ast_log(LOG_WARNING, "Could not find application! (%s)\n", apps.f); 00273 res = -1; 00274 } 00275 } 00276 00277 return res; 00278 }
static int load_module | ( | void | ) | [static] |
Definition at line 291 of file app_exec.c.
References ast_register_application_xml, exec_exec(), execif_exec(), and tryexec_exec().
00292 { 00293 int res = ast_register_application_xml(app_exec, exec_exec); 00294 res |= ast_register_application_xml(app_tryexec, tryexec_exec); 00295 res |= ast_register_application_xml(app_execif, execif_exec); 00296 return res; 00297 }
static int tryexec_exec | ( | struct ast_channel * | chan, | |
const char * | data | |||
) | [static] |
Definition at line 166 of file app_exec.c.
References app, args, ast_free, ast_log(), ast_str_buffer(), ast_str_create(), ast_str_substitute_variables(), ast_strdupa, ast_strlen_zero(), LOG_WARNING, pbx_builtin_setvar_helper(), pbx_exec(), pbx_findapp(), and strsep().
Referenced by load_module().
00167 { 00168 int res = 0; 00169 char *s, *appname, *endargs; 00170 struct ast_app *app; 00171 struct ast_str *args = NULL; 00172 00173 if (ast_strlen_zero(data)) 00174 return 0; 00175 00176 s = ast_strdupa(data); 00177 appname = strsep(&s, "("); 00178 if (s) { 00179 endargs = strrchr(s, ')'); 00180 if (endargs) 00181 *endargs = '\0'; 00182 if ((args = ast_str_create(16))) { 00183 ast_str_substitute_variables(&args, 0, chan, s); 00184 } 00185 } 00186 if (appname) { 00187 app = pbx_findapp(appname); 00188 if (app) { 00189 res = pbx_exec(chan, app, args ? ast_str_buffer(args) : NULL); 00190 pbx_builtin_setvar_helper(chan, "TRYSTATUS", res ? "FAILED" : "SUCCESS"); 00191 } else { 00192 ast_log(LOG_WARNING, "Could not find application (%s)\n", appname); 00193 pbx_builtin_setvar_helper(chan, "TRYSTATUS", "NOAPP"); 00194 } 00195 } 00196 00197 ast_free(args); 00198 return 0; 00199 }
static int unload_module | ( | void | ) | [static] |
Definition at line 280 of file app_exec.c.
References ast_unregister_application().
00281 { 00282 int res; 00283 00284 res = ast_unregister_application(app_exec); 00285 res |= ast_unregister_application(app_tryexec); 00286 res |= ast_unregister_application(app_execif); 00287 00288 return res; 00289 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static] |
Definition at line 299 of file app_exec.c.
const 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.
Referenced by load_module().
const char app_execif[] = "ExecIf" [static] |
Definition at line 130 of file app_exec.c.
const 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 299 of file app_exec.c.