app_exec.c File Reference

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"

Include dependency graph for app_exec.c:

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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static const char app_exec [] = "Exec"
static const char app_execif [] = "ExecIf"
static const char app_tryexec [] = "TryExec"
static struct ast_module_infoast_module_info = &__mod_info


Detailed Description

Exec application.

Author:
Tilghman Lesher <app_exec__v002@the-tilghman.com>

Philipp Dunkel <philipp.dunkel@ebox.at>

Definition in file app_exec.c.


Define Documentation

#define MAXRESULT   1024

Definition at line 117 of file app_exec.c.

Referenced by substituted().


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 302 of file app_exec.c.

static void __unreg_module ( void   )  [static]

Definition at line 302 of file app_exec.c.

static int exec_exec ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 135 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, NULL, pbx_exec(), pbx_findapp(), and strsep().

Referenced by load_module().

00136 {
00137    int res = 0;
00138    char *s, *appname, *endargs;
00139    struct ast_app *app;
00140    struct ast_str *args = NULL;
00141 
00142    if (ast_strlen_zero(data))
00143       return 0;
00144 
00145    s = ast_strdupa(data);
00146    appname = strsep(&s, "(");
00147    if (s) {
00148       endargs = strrchr(s, ')');
00149       if (endargs)
00150          *endargs = '\0';
00151       if ((args = ast_str_create(16))) {
00152          ast_str_substitute_variables(&args, 0, chan, s);
00153       }
00154    }
00155    if (appname) {
00156       app = pbx_findapp(appname);
00157       if (app) {
00158          res = pbx_exec(chan, app, args ? ast_str_buffer(args) : NULL);
00159       } else {
00160          ast_log(LOG_WARNING, "Could not find application (%s)\n", appname);
00161          res = -1;
00162       }
00163    }
00164 
00165    ast_free(args);
00166    return res;
00167 }

static int execif_exec ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 204 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, end, f, LOG_ERROR, LOG_WARNING, NULL, parse(), pbx_checkcondition(), pbx_exec(), pbx_findapp(), and S_OR.

Referenced by load_module().

00205 {
00206    int res = 0;
00207    char *truedata = NULL, *falsedata = NULL, *end, *firstcomma, *firstquestion;
00208    struct ast_app *app = NULL;
00209    AST_DECLARE_APP_ARGS(expr,
00210       AST_APP_ARG(expr);
00211       AST_APP_ARG(remainder);
00212    );
00213    AST_DECLARE_APP_ARGS(apps,
00214       AST_APP_ARG(t);
00215       AST_APP_ARG(f);
00216    );
00217    char *parse = ast_strdupa(data);
00218 
00219    firstcomma = strchr(parse, ',');
00220    firstquestion = strchr(parse, '?');
00221 
00222    if ((firstcomma != NULL && firstquestion != NULL && firstcomma < firstquestion) || (firstquestion == NULL)) {
00223       /* Deprecated syntax */
00224       AST_DECLARE_APP_ARGS(depr,
00225          AST_APP_ARG(expr);
00226          AST_APP_ARG(appname);
00227          AST_APP_ARG(appargs);
00228       );
00229       AST_STANDARD_APP_ARGS(depr, parse);
00230 
00231       ast_log(LOG_WARNING, "Deprecated syntax found.  Please upgrade to using ExecIf(<expr>?%s(%s))\n", depr.appname, depr.appargs);
00232 
00233       /* Make the two syntaxes look the same */
00234       expr.expr = depr.expr;
00235       apps.t = depr.appname;
00236       apps.f = NULL;
00237       truedata = depr.appargs;
00238    } else {
00239       /* Preferred syntax */
00240 
00241       AST_NONSTANDARD_RAW_ARGS(expr, parse, '?');
00242       if (ast_strlen_zero(expr.remainder)) {
00243          ast_log(LOG_ERROR, "Usage: ExecIf(<expr>?<appiftrue>(<args>)[:<appiffalse>(<args)])\n");
00244          return -1;
00245       }
00246 
00247       AST_NONSTANDARD_RAW_ARGS(apps, expr.remainder, ':');
00248 
00249       if (apps.t && (truedata = strchr(apps.t, '('))) {
00250          *truedata++ = '\0';
00251          if ((end = strrchr(truedata, ')'))) {
00252             *end = '\0';
00253          }
00254       }
00255 
00256       if (apps.f && (falsedata = strchr(apps.f, '('))) {
00257          *falsedata++ = '\0';
00258          if ((end = strrchr(falsedata, ')'))) {
00259             *end = '\0';
00260          }
00261       }
00262    }
00263 
00264    if (pbx_checkcondition(expr.expr)) {
00265       if (!ast_strlen_zero(apps.t) && (app = pbx_findapp(apps.t))) {
00266          res = pbx_exec(chan, app, S_OR(truedata, ""));
00267       } else {
00268          ast_log(LOG_WARNING, "Could not find application! (%s)\n", apps.t);
00269          res = -1;
00270       }
00271    } else if (!ast_strlen_zero(apps.f)) {
00272       if ((app = pbx_findapp(apps.f))) {
00273          res = pbx_exec(chan, app, S_OR(falsedata, ""));
00274       } else {
00275          ast_log(LOG_WARNING, "Could not find application! (%s)\n", apps.f);
00276          res = -1;
00277       }
00278    }
00279 
00280    return res;
00281 }

static int load_module ( void   )  [static]

static int tryexec_exec ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 169 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, NULL, pbx_builtin_setvar_helper(), pbx_exec(), pbx_findapp(), and strsep().

Referenced by load_module().

00170 {
00171    int res = 0;
00172    char *s, *appname, *endargs;
00173    struct ast_app *app;
00174    struct ast_str *args = NULL;
00175 
00176    if (ast_strlen_zero(data))
00177       return 0;
00178 
00179    s = ast_strdupa(data);
00180    appname = strsep(&s, "(");
00181    if (s) {
00182       endargs = strrchr(s, ')');
00183       if (endargs)
00184          *endargs = '\0';
00185       if ((args = ast_str_create(16))) {
00186          ast_str_substitute_variables(&args, 0, chan, s);
00187       }
00188    }
00189    if (appname) {
00190       app = pbx_findapp(appname);
00191       if (app) {
00192          res = pbx_exec(chan, app, args ? ast_str_buffer(args) : NULL);
00193          pbx_builtin_setvar_helper(chan, "TRYSTATUS", res ? "FAILED" : "SUCCESS");
00194       } else {
00195          ast_log(LOG_WARNING, "Could not find application (%s)\n", appname);
00196          pbx_builtin_setvar_helper(chan, "TRYSTATUS", "NOAPP");
00197       }
00198    }
00199 
00200    ast_free(args);
00201    return 0;
00202 }

static int unload_module ( void   )  [static]

Definition at line 283 of file app_exec.c.

References ast_unregister_application().

00284 {
00285    int res;
00286 
00287    res = ast_unregister_application(app_exec);
00288    res |= ast_unregister_application(app_tryexec);
00289    res |= ast_unregister_application(app_execif);
00290 
00291    return res;
00292 }


Variable Documentation

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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, } [static]

Definition at line 302 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 131 of file app_exec.c.

Referenced by load_module().

const char app_execif[] = "ExecIf" [static]

Definition at line 133 of file app_exec.c.

const char app_tryexec[] = "TryExec" [static]

Definition at line 132 of file app_exec.c.

Definition at line 302 of file app_exec.c.


Generated on Thu Apr 16 06:28:27 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6