#include "asterisk.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/options.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.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 | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .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" |
Philipp Dunkel <philipp.dunkel@ebox.at>
Definition in file app_exec.c.
#define MAXRESULT 1024 |
Definition at line 46 of file app_exec.c.
static void __reg_module | ( | void | ) | [static] |
Definition at line 221 of file app_exec.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 221 of file app_exec.c.
static int exec_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 91 of file app_exec.c.
References app, ast_log(), ast_module_user_add, ast_module_user_remove, ast_strdupa, LOG_WARNING, MAXRESULT, pbx_exec(), pbx_findapp(), pbx_substitute_variables_helper(), and s.
Referenced by load_module().
00092 { 00093 int res=0; 00094 struct ast_module_user *u; 00095 char *s, *appname, *endargs, args[MAXRESULT] = ""; 00096 struct ast_app *app; 00097 00098 u = ast_module_user_add(chan); 00099 00100 /* Check and parse arguments */ 00101 if (data) { 00102 s = ast_strdupa(data); 00103 appname = strsep(&s, "("); 00104 if (s) { 00105 endargs = strrchr(s, ')'); 00106 if (endargs) 00107 *endargs = '\0'; 00108 pbx_substitute_variables_helper(chan, s, args, MAXRESULT - 1); 00109 } 00110 if (appname) { 00111 app = pbx_findapp(appname); 00112 if (app) { 00113 res = pbx_exec(chan, app, args); 00114 } else { 00115 ast_log(LOG_WARNING, "Could not find application (%s)\n", appname); 00116 res = -1; 00117 } 00118 } 00119 } 00120 00121 ast_module_user_remove(u); 00122 return res; 00123 }
static int execif_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 160 of file app_exec.c.
References app, ast_log(), ast_module_user_add, ast_module_user_remove, ast_strdupa, LOG_ERROR, LOG_WARNING, pbx_checkcondition(), pbx_exec(), and pbx_findapp().
Referenced by load_module().
00161 { 00162 int res = 0; 00163 struct ast_module_user *u; 00164 char *myapp = NULL; 00165 char *mydata = NULL; 00166 char *expr = NULL; 00167 struct ast_app *app = NULL; 00168 00169 u = ast_module_user_add(chan); 00170 00171 expr = ast_strdupa(data); 00172 00173 if ((myapp = strchr(expr,'|'))) { 00174 *myapp = '\0'; 00175 myapp++; 00176 if ((mydata = strchr(myapp,'|'))) { 00177 *mydata = '\0'; 00178 mydata++; 00179 } else 00180 mydata = ""; 00181 00182 if (pbx_checkcondition(expr)) { 00183 if ((app = pbx_findapp(myapp))) { 00184 res = pbx_exec(chan, app, mydata); 00185 } else { 00186 ast_log(LOG_WARNING, "Could not find application! (%s)\n", myapp); 00187 res = -1; 00188 } 00189 } 00190 } else { 00191 ast_log(LOG_ERROR,"Invalid Syntax.\n"); 00192 res = -1; 00193 } 00194 00195 ast_module_user_remove(u); 00196 00197 return res; 00198 }
static int load_module | ( | void | ) | [static] |
Definition at line 213 of file app_exec.c.
References ast_register_application(), exec_exec(), execif_exec(), and tryexec_exec().
00214 { 00215 int res = ast_register_application(app_exec, exec_exec, exec_synopsis, exec_descrip); 00216 res |= ast_register_application(app_tryexec, tryexec_exec, tryexec_synopsis, tryexec_descrip); 00217 res |= ast_register_application(app_execif, execif_exec, execif_synopsis, execif_descrip); 00218 return res; 00219 }
static int tryexec_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 125 of file app_exec.c.
References app, ast_log(), ast_module_user_add, ast_module_user_remove, ast_strdupa, LOG_WARNING, MAXRESULT, pbx_builtin_setvar_helper(), pbx_exec(), pbx_findapp(), pbx_substitute_variables_helper(), and s.
Referenced by load_module().
00126 { 00127 int res=0; 00128 struct ast_module_user *u; 00129 char *s, *appname, *endargs, args[MAXRESULT] = ""; 00130 struct ast_app *app; 00131 00132 u = ast_module_user_add(chan); 00133 00134 /* Check and parse arguments */ 00135 if (data) { 00136 s = ast_strdupa(data); 00137 appname = strsep(&s, "("); 00138 if (s) { 00139 endargs = strrchr(s, ')'); 00140 if (endargs) 00141 *endargs = '\0'; 00142 pbx_substitute_variables_helper(chan, s, args, MAXRESULT - 1); 00143 } 00144 if (appname) { 00145 app = pbx_findapp(appname); 00146 if (app) { 00147 res = pbx_exec(chan, app, args); 00148 pbx_builtin_setvar_helper(chan, "TRYSTATUS", res ? "FAILED" : "SUCCESS"); 00149 } else { 00150 ast_log(LOG_WARNING, "Could not find application (%s)\n", appname); 00151 pbx_builtin_setvar_helper(chan, "TRYSTATUS", "NOAPP"); 00152 } 00153 } 00154 } 00155 00156 ast_module_user_remove(u); 00157 return 0; 00158 }
static int unload_module | ( | void | ) | [static] |
Definition at line 200 of file app_exec.c.
References ast_module_user_hangup_all, and ast_unregister_application().
00201 { 00202 int res; 00203 00204 res = ast_unregister_application(app_exec); 00205 res |= ast_unregister_application(app_tryexec); 00206 res |= ast_unregister_application(app_execif); 00207 00208 ast_module_user_hangup_all(); 00209 00210 return res; 00211 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 221 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 60 of file app_exec.c.
Referenced by load_module().
char* app_execif = "ExecIf" [static] |
Definition at line 83 of file app_exec.c.
char* app_tryexec = "TryExec" [static] |
Definition at line 71 of file app_exec.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 221 of file app_exec.c.
char* exec_descrip [static] |
Definition at line 62 of file app_exec.c.
char* exec_synopsis = "Executes dialplan application" [static] |
Definition at line 61 of file app_exec.c.
char* execif_descrip [static] |
Initial value:
"Usage: ExecIF (<expr>|<app>|<data>)\n" "If <expr> is true, execute and return the result of <app>(<data>).\n" "If <expr> is true, but <app> is not found, then the application\n" "will return a non-zero value.\n"
Definition at line 85 of file app_exec.c.
char* execif_synopsis = "Executes dialplan application, conditionally" [static] |
Definition at line 84 of file app_exec.c.
char* tryexec_descrip [static] |
Definition at line 73 of file app_exec.c.
char* tryexec_synopsis = "Executes dialplan application, always returning" [static] |
Definition at line 72 of file app_exec.c.