#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/app.h"
#include "asterisk/options.h"
Include dependency graph for app_system.c:
Go to the source code of this file.
Functions | |
AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Generic System() application") | |
static int | load_module (void) |
static int | system_exec (struct ast_channel *chan, void *data) |
static int | system_exec_helper (struct ast_channel *chan, void *data, int failmode) |
static int | trysystem_exec (struct ast_channel *chan, void *data) |
static int | unload_module (void) |
Variables | |
static char * | app = "System" |
static char * | app2 = "TrySystem" |
static char * | chanvar = "SYSTEMSTATUS" |
static char * | descrip |
static char * | descrip2 |
static char * | synopsis = "Execute a system command" |
static char * | synopsis2 = "Try executing a system command" |
Definition in file app_system.c.
AST_MODULE_INFO_STANDARD | ( | ASTERISK_GPL_KEY | , | |
"Generic System() application" | ||||
) |
static int load_module | ( | void | ) | [static] |
Definition at line 152 of file app_system.c.
References ast_register_application(), system_exec(), and trysystem_exec().
00153 { 00154 int res; 00155 00156 res = ast_register_application(app2, trysystem_exec, synopsis2, descrip2); 00157 res |= ast_register_application(app, system_exec, synopsis, descrip); 00158 00159 return res; 00160 }
static int system_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 130 of file app_system.c.
References ast_module_user::chan, and system_exec_helper().
Referenced by load_module().
00131 { 00132 return system_exec_helper(chan, data, -1); 00133 }
static int system_exec_helper | ( | struct ast_channel * | chan, | |
void * | data, | |||
int | failmode | |||
) | [static] |
Definition at line 85 of file app_system.c.
References ast_autoservice_start(), ast_autoservice_stop(), ast_goto_if_exists(), ast_log(), ast_module_user_add, ast_module_user_remove, ast_opt_priority_jumping, ast_safe_system(), ast_strlen_zero(), ast_module_user::chan, ast_channel::context, errno, LOG_WARNING, and pbx_builtin_setvar_helper().
Referenced by system_exec(), and trysystem_exec().
00086 { 00087 int res=0; 00088 struct ast_module_user *u; 00089 00090 if (ast_strlen_zero(data)) { 00091 ast_log(LOG_WARNING, "System requires an argument(command)\n"); 00092 pbx_builtin_setvar_helper(chan, chanvar, "FAILURE"); 00093 return failmode; 00094 } 00095 00096 u = ast_module_user_add(chan); 00097 00098 ast_autoservice_start(chan); 00099 00100 /* Do our thing here */ 00101 res = ast_safe_system((char *)data); 00102 if ((res < 0) && (errno != ECHILD)) { 00103 ast_log(LOG_WARNING, "Unable to execute '%s'\n", (char *)data); 00104 pbx_builtin_setvar_helper(chan, chanvar, "FAILURE"); 00105 res = failmode; 00106 } else if (res == 127) { 00107 ast_log(LOG_WARNING, "Unable to execute '%s'\n", (char *)data); 00108 pbx_builtin_setvar_helper(chan, chanvar, "FAILURE"); 00109 res = failmode; 00110 } else { 00111 if (res < 0) 00112 res = 0; 00113 if (ast_opt_priority_jumping && res) 00114 ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101); 00115 00116 if (res != 0) 00117 pbx_builtin_setvar_helper(chan, chanvar, "APPERROR"); 00118 else 00119 pbx_builtin_setvar_helper(chan, chanvar, "SUCCESS"); 00120 res = 0; 00121 } 00122 00123 ast_autoservice_stop(chan); 00124 00125 ast_module_user_remove(u); 00126 00127 return res; 00128 }
static int trysystem_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 135 of file app_system.c.
References ast_module_user::chan, and system_exec_helper().
Referenced by load_module().
00136 { 00137 return system_exec_helper(chan, data, 0); 00138 }
static int unload_module | ( | void | ) | [static] |
Definition at line 140 of file app_system.c.
References ast_module_user_hangup_all, and ast_unregister_application().
00141 { 00142 int res; 00143 00144 res = ast_unregister_application(app); 00145 res |= ast_unregister_application(app2); 00146 00147 ast_module_user_hangup_all(); 00148 00149 return res; 00150 }
char* app = "System" [static] |
Definition at line 47 of file app_system.c.
char* app2 = "TrySystem" [static] |
Definition at line 49 of file app_system.c.
char* chanvar = "SYSTEMSTATUS" [static] |
Definition at line 55 of file app_system.c.
char* descrip [static] |
Definition at line 57 of file app_system.c.
char* descrip2 [static] |
Definition at line 71 of file app_system.c.
char* synopsis = "Execute a system command" [static] |
Definition at line 51 of file app_system.c.
char* synopsis2 = "Try executing a system command" [static] |
Definition at line 53 of file app_system.c.