Asterisk - The Open Source Telephony Project GIT-master-754dea3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
Macros | Functions | Variables
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.

Macros

#define MAXRESULT   1024
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (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 const struct ast_module_infoast_module_info = &__mod_info
 

Detailed Description

Exec application.

Author
Tilghman Lesher app_e.nosp@m.xec_.nosp@m._v002.nosp@m.@the.nosp@m.-tilg.nosp@m.hman.nosp@m..com
Philipp Dunkel phili.nosp@m.pp.d.nosp@m.unkel.nosp@m.@ebo.nosp@m.x.at

Definition in file app_exec.c.

Macro Definition Documentation

◆ MAXRESULT

#define MAXRESULT   1024

Definition at line 124 of file app_exec.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 309 of file app_exec.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 309 of file app_exec.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 309 of file app_exec.c.

◆ exec_exec()

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

Definition at line 142 of file app_exec.c.

143{
144 int res = 0;
145 char *s, *appname, *endargs;
146 struct ast_app *app;
147 struct ast_str *args = NULL;
148
149 if (ast_strlen_zero(data))
150 return 0;
151
152 s = ast_strdupa(data);
153 appname = strsep(&s, "(");
154 if (s) {
155 endargs = strrchr(s, ')');
156 if (endargs)
157 *endargs = '\0';
158 if ((args = ast_str_create(16))) {
160 }
161 }
162 if (appname) {
163 app = pbx_findapp(appname);
164 if (app) {
165 res = pbx_exec(chan, app, args ? ast_str_buffer(args) : NULL);
166 } else {
167 ast_log(LOG_WARNING, "Could not find application (%s)\n", appname);
168 res = -1;
169 }
170 }
171
172 ast_free(args);
173 return res;
174}
static const char app[]
Definition: app_adsiprog.c:56
char * strsep(char **str, const char *delims)
#define ast_free(a)
Definition: astmm.h:180
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_log
Definition: astobj2.c:42
#define LOG_WARNING
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
int pbx_exec(struct ast_channel *c, struct ast_app *app, const char *data)
Execute an application.
Definition: pbx_app.c:471
struct ast_app * pbx_findapp(const char *app)
Look up an application.
Definition: ael_main.c:165
#define NULL
Definition: resample.c:96
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
ast_app: A registered application
Definition: pbx_app.c:45
Support for dynamic strings.
Definition: strings.h:623
const char * args

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().

◆ execif_exec()

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

Definition at line 211 of file app_exec.c.

212{
213 int res = 0;
214 char *truedata = NULL, *falsedata = NULL, *end, *firstcomma, *firstquestion;
215 struct ast_app *app = NULL;
217 AST_APP_ARG(expr);
218 AST_APP_ARG(remainder);
219 );
221 AST_APP_ARG(t);
222 AST_APP_ARG(f);
223 );
224 char *parse = ast_strdupa(data);
225
226 firstcomma = strchr(parse, ',');
227 firstquestion = strchr(parse, '?');
228
229 if ((firstcomma != NULL && firstquestion != NULL && firstcomma < firstquestion) || (firstquestion == NULL)) {
230 /* Deprecated syntax */
232 AST_APP_ARG(expr);
233 AST_APP_ARG(appname);
234 AST_APP_ARG(appargs);
235 );
236 AST_STANDARD_APP_ARGS(depr, parse);
237
238 ast_log(LOG_WARNING, "Deprecated syntax found. Please upgrade to using ExecIf(<expr>?%s(%s))\n", depr.appname, depr.appargs);
239
240 /* Make the two syntaxes look the same */
241 expr.expr = depr.expr;
242 apps.t = depr.appname;
243 apps.f = NULL;
244 truedata = depr.appargs;
245 } else {
246 /* Preferred syntax */
247
248 AST_NONSTANDARD_RAW_ARGS(expr, parse, '?');
249 if (ast_strlen_zero(expr.remainder)) {
250 ast_log(LOG_ERROR, "Usage: ExecIf(<expr>?<appiftrue>(<args>)[:<appiffalse>(<args)])\n");
251 return -1;
252 }
253
254 AST_NONSTANDARD_RAW_ARGS(apps, expr.remainder, ':');
255
256 if (apps.t && (truedata = strchr(apps.t, '('))) {
257 *truedata++ = '\0';
258 if ((end = strrchr(truedata, ')'))) {
259 *end = '\0';
260 }
261 }
262
263 if (apps.f && (falsedata = strchr(apps.f, '('))) {
264 *falsedata++ = '\0';
265 if ((end = strrchr(falsedata, ')'))) {
266 *end = '\0';
267 }
268 }
269 }
270
271 if (pbx_checkcondition(expr.expr)) {
272 if (!ast_strlen_zero(apps.t) && (app = pbx_findapp(apps.t))) {
273 res = pbx_exec(chan, app, S_OR(truedata, ""));
274 } else {
275 ast_log(LOG_WARNING, "Could not find application! (%s)\n", apps.t);
276 res = -1;
277 }
278 } else if (!ast_strlen_zero(apps.f)) {
279 if ((app = pbx_findapp(apps.f))) {
280 res = pbx_exec(chan, app, S_OR(falsedata, ""));
281 } else {
282 ast_log(LOG_WARNING, "Could not find application! (%s)\n", apps.f);
283 res = -1;
284 }
285 }
286
287 return res;
288}
char * end
Definition: eagi_proxy.c:73
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define AST_NONSTANDARD_RAW_ARGS(args, parse, sep)
#define LOG_ERROR
int pbx_checkcondition(const char *condition)
Evaluate a condition.
Definition: pbx.c:8297
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:80
Registered applications container.
Definition: pbx_app.c:68

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, LOG_ERROR, LOG_WARNING, NULL, pbx_checkcondition(), pbx_exec(), pbx_findapp(), and S_OR.

Referenced by load_module().

◆ load_module()

static int load_module ( void  )
static

Definition at line 301 of file app_exec.c.

302{
306 return res;
307}
static int tryexec_exec(struct ast_channel *chan, const char *data)
Definition: app_exec.c:176
static const char app_execif[]
Definition: app_exec.c:140
static int execif_exec(struct ast_channel *chan, const char *data)
Definition: app_exec.c:211
static const char app_exec[]
Definition: app_exec.c:138
static const char app_tryexec[]
Definition: app_exec.c:139
static int exec_exec(struct ast_channel *chan, const char *data)
Definition: app_exec.c:142
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:640

References app_exec, app_execif, app_tryexec, ast_register_application_xml, exec_exec(), execif_exec(), and tryexec_exec().

◆ tryexec_exec()

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

Definition at line 176 of file app_exec.c.

177{
178 int res = 0;
179 char *s, *appname, *endargs;
180 struct ast_app *app;
181 struct ast_str *args = NULL;
182
183 if (ast_strlen_zero(data))
184 return 0;
185
186 s = ast_strdupa(data);
187 appname = strsep(&s, "(");
188 if (s) {
189 endargs = strrchr(s, ')');
190 if (endargs)
191 *endargs = '\0';
192 if ((args = ast_str_create(16))) {
194 }
195 }
196 if (appname) {
197 app = pbx_findapp(appname);
198 if (app) {
199 res = pbx_exec(chan, app, args ? ast_str_buffer(args) : NULL);
200 pbx_builtin_setvar_helper(chan, "TRYSTATUS", res ? "FAILED" : "SUCCESS");
201 } else {
202 ast_log(LOG_WARNING, "Could not find application (%s)\n", appname);
203 pbx_builtin_setvar_helper(chan, "TRYSTATUS", "NOAPP");
204 }
205 }
206
207 ast_free(args);
208 return 0;
209}
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name.

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().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 290 of file app_exec.c.

291{
292 int res;
293
297
298 return res;
299}
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392

References app_exec, app_execif, app_tryexec, and ast_unregister_application().

Variable Documentation

◆ __mod_info

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

◆ app_exec

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

Referenced by load_module(), and unload_module().

◆ app_execif

const char app_execif[] = "ExecIf"
static

Definition at line 140 of file app_exec.c.

Referenced by load_module(), and unload_module().

◆ app_tryexec

const char app_tryexec[] = "TryExec"
static

Definition at line 139 of file app_exec.c.

Referenced by load_module(), and unload_module().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 309 of file app_exec.c.