Wed Oct 28 11:45:44 2009

Asterisk developer's documentation


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, 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 = 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 const struct
ast_module_info
ast_module_info = &__mod_info
static char * exec_descrip
static char * exec_synopsis = "Executes dialplan application"
static char * execif_descrip
static char * execif_synopsis = "Executes dialplan application, conditionally"
static char * tryexec_descrip
static char * tryexec_synopsis = "Executes dialplan application, always returning"


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 40 of file app_exec.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 246 of file app_exec.c.

static void __unreg_module ( void   )  [static]

Definition at line 246 of file app_exec.c.

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

Definition at line 85 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().

00086 {
00087    int res = 0;
00088    char *s, *appname, *endargs, args[MAXRESULT];
00089    struct ast_app *app;
00090 
00091    if (ast_strlen_zero(data))
00092       return 0;
00093 
00094    s = ast_strdupa(data);
00095    args[0] = 0;
00096    appname = strsep(&s, "(");
00097    if (s) {
00098       endargs = strrchr(s, ')');
00099       if (endargs)
00100          *endargs = '\0';
00101       pbx_substitute_variables_helper(chan, s, args, MAXRESULT - 1);
00102    }
00103    if (appname) {
00104       app = pbx_findapp(appname);
00105       if (app) {
00106          res = pbx_exec(chan, app, args);
00107       } else {
00108          ast_log(LOG_WARNING, "Could not find application (%s)\n", appname);
00109          res = -1;
00110       }
00111    }
00112 
00113    return res;
00114 }

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

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

Referenced by load_module().

00149 {
00150    int res = 0;
00151    char *truedata = NULL, *falsedata = NULL, *end, *firstcomma, *firstquestion;
00152    struct ast_app *app = NULL;
00153    AST_DECLARE_APP_ARGS(expr,
00154       AST_APP_ARG(expr);
00155       AST_APP_ARG(remainder);
00156    );
00157    AST_DECLARE_APP_ARGS(apps,
00158       AST_APP_ARG(t);
00159       AST_APP_ARG(f);
00160    );
00161    char *parse = ast_strdupa(data);
00162 
00163    firstcomma = strchr(parse, ',');
00164    firstquestion = strchr(parse, '?');
00165 
00166    if ((firstcomma != NULL && firstquestion != NULL && firstcomma < firstquestion) || (firstquestion == NULL)) {
00167       /* Deprecated syntax */
00168       AST_DECLARE_APP_ARGS(depr,
00169          AST_APP_ARG(expr);
00170          AST_APP_ARG(appname);
00171          AST_APP_ARG(appargs);
00172       );
00173       AST_STANDARD_APP_ARGS(depr, parse);
00174 
00175       ast_log(LOG_WARNING, "Deprecated syntax found.  Please upgrade to using ExecIf(<expr>?%s(%s))\n", depr.appname, depr.appargs);
00176 
00177       /* Make the two syntaxes look the same */
00178       expr.expr = depr.expr;
00179       apps.t = depr.appname;
00180       apps.f = NULL;
00181       truedata = depr.appargs;
00182    } else {
00183       /* Preferred syntax */
00184 
00185       AST_NONSTANDARD_APP_ARGS(expr, parse, '?');
00186       if (ast_strlen_zero(expr.remainder)) {
00187          ast_log(LOG_ERROR, "Usage: ExecIf(<expr>?<appiftrue>(<args>)[:<appiffalse>(<args)])\n");
00188          return -1;
00189       }
00190 
00191       AST_NONSTANDARD_APP_ARGS(apps, expr.remainder, ':');
00192 
00193       if (apps.t && (truedata = strchr(apps.t, '('))) {
00194          *truedata++ = '\0';
00195          if ((end = strrchr(truedata, ')'))) {
00196             *end = '\0';
00197          }
00198       }
00199 
00200       if (apps.f && (falsedata = strchr(apps.f, '('))) {
00201          *falsedata++ = '\0';
00202          if ((end = strrchr(falsedata, ')'))) {
00203             *end = '\0';
00204          }
00205       }
00206    }
00207 
00208    if (pbx_checkcondition(expr.expr)) {
00209       if (!ast_strlen_zero(apps.t) && (app = pbx_findapp(apps.t))) {
00210          res = pbx_exec(chan, app, S_OR(truedata, ""));
00211       } else {
00212          ast_log(LOG_WARNING, "Could not find application! (%s)\n", apps.t);
00213          res = -1;
00214       }
00215    } else if (!ast_strlen_zero(apps.f)) {
00216       if ((app = pbx_findapp(apps.f))) {
00217          res = pbx_exec(chan, app, S_OR(falsedata, ""));
00218       } else {
00219          ast_log(LOG_WARNING, "Could not find application! (%s)\n", apps.f);
00220          res = -1;
00221       }
00222    }
00223 
00224    return res;
00225 }

static int load_module ( void   )  [static]

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

Definition at line 116 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().

00117 {
00118    int res = 0;
00119    char *s, *appname, *endargs, args[MAXRESULT];
00120    struct ast_app *app;
00121 
00122    if (ast_strlen_zero(data))
00123       return 0;
00124 
00125    s = ast_strdupa(data);
00126    args[0] = 0;
00127    appname = strsep(&s, "(");
00128    if (s) {
00129       endargs = strrchr(s, ')');
00130       if (endargs)
00131          *endargs = '\0';
00132       pbx_substitute_variables_helper(chan, s, args, MAXRESULT - 1);
00133    }
00134    if (appname) {
00135       app = pbx_findapp(appname);
00136       if (app) {
00137          res = pbx_exec(chan, app, args);
00138          pbx_builtin_setvar_helper(chan, "TRYSTATUS", res ? "FAILED" : "SUCCESS");
00139       } else {
00140          ast_log(LOG_WARNING, "Could not find application (%s)\n", appname);
00141          pbx_builtin_setvar_helper(chan, "TRYSTATUS", "NOAPP");
00142       }
00143    }
00144 
00145    return 0;
00146 }

static int unload_module ( void   )  [static]

Definition at line 227 of file app_exec.c.

References ast_unregister_application().

00228 {
00229    int res;
00230 
00231    res = ast_unregister_application(app_exec);
00232    res |= ast_unregister_application(app_tryexec);
00233    res |= ast_unregister_application(app_execif);
00234 
00235    return res;
00236 }


Variable Documentation

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

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

Referenced by load_module().

char* app_execif = "ExecIf" [static]

Definition at line 77 of file app_exec.c.

char* app_tryexec = "TryExec" [static]

Definition at line 65 of file app_exec.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 246 of file app_exec.c.

char* exec_descrip [static]

Definition at line 56 of file app_exec.c.

char* exec_synopsis = "Executes dialplan application" [static]

Definition at line 55 of file app_exec.c.

char* execif_descrip [static]

Initial value:

"  ExecIF (<expr>?<appiftrue>(<args>)[:<appiffalse>(<args>)])\n"
"If <expr> is true, execute and return the result of <appiftrue>(<args>).\n"
"If <expr> is true, but <appiftrue> is not found, then the application\n"
"will return a non-zero value.\n"

Definition at line 79 of file app_exec.c.

char* execif_synopsis = "Executes dialplan application, conditionally" [static]

Definition at line 78 of file app_exec.c.

char* tryexec_descrip [static]

Definition at line 67 of file app_exec.c.

char* tryexec_synopsis = "Executes dialplan application, always returning" [static]

Definition at line 66 of file app_exec.c.


Generated on Wed Oct 28 11:45:44 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6