#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "asterisk.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"
Go to the source code of this file.
Functions | |
char * | description (void) |
Provides a description of the module. | |
char * | key () |
Returns the ASTERISK_GPL_KEY. | |
int | load_module (void) |
Initialize the module. | |
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) |
int | unload_module (void) |
Cleanup all module structures, sockets, etc. | |
int | usecount (void) |
Provides a usecount. | |
Variables | |
static char * | app = "System" |
static char * | app2 = "TrySystem" |
static char * | chanvar = "SYSTEMSTATUS" |
static char * | descrip |
static char * | descrip2 |
LOCAL_USER_DECL | |
STANDARD_LOCAL_USER | |
static char * | synopsis = "Execute a system command" |
static char * | synopsis2 = "Try executing a system command" |
static char * | tdesc = "Generic System() application" |
Definition in file app_system.c.
char* description | ( | void | ) |
Provides a description of the module.
Definition at line 161 of file app_system.c.
00162 { 00163 return tdesc; 00164 }
char* key | ( | void | ) |
Returns the ASTERISK_GPL_KEY.
This returns the ASTERISK_GPL_KEY, signifiying that you agree to the terms of the GPL stated in the ASTERISK_GPL_KEY. Your module will not load if it does not return the EXACT message:
char *key(void) { return ASTERISK_GPL_KEY; }
Definition at line 173 of file app_system.c.
References ASTERISK_GPL_KEY.
00174 { 00175 return ASTERISK_GPL_KEY; 00176 }
int load_module | ( | void | ) |
Initialize the module.
Initialize the Agents module. This function is being called by Asterisk when loading the module. Among other thing it registers applications, cli commands and reads the cofiguration file.
Definition at line 151 of file app_system.c.
References ast_register_application(), system_exec(), and trysystem_exec().
00152 { 00153 int res; 00154 00155 res = ast_register_application(app2, trysystem_exec, synopsis2, descrip2); 00156 res |= ast_register_application(app, system_exec, synopsis, descrip); 00157 00158 return res; 00159 }
static int system_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 129 of file app_system.c.
References localuser::chan, and system_exec_helper().
Referenced by load_module().
00130 { 00131 return system_exec_helper(chan, data, -1); 00132 }
static int system_exec_helper | ( | struct ast_channel * | chan, | |
void * | data, | |||
int | failmode | |||
) | [static] |
Definition at line 88 of file app_system.c.
References ast_goto_if_exists(), ast_log(), ast_safe_system(), ast_strlen_zero(), localuser::chan, ast_channel::context, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_WARNING, option_priority_jumping, and pbx_builtin_setvar_helper().
Referenced by system_exec(), and trysystem_exec().
00089 { 00090 int res=0; 00091 struct localuser *u; 00092 00093 if (ast_strlen_zero(data)) { 00094 ast_log(LOG_WARNING, "System requires an argument(command)\n"); 00095 pbx_builtin_setvar_helper(chan, chanvar, "FAILURE"); 00096 return failmode; 00097 } 00098 00099 LOCAL_USER_ADD(u); 00100 00101 /* Do our thing here */ 00102 res = ast_safe_system((char *)data); 00103 if ((res < 0) && (errno != ECHILD)) { 00104 ast_log(LOG_WARNING, "Unable to execute '%s'\n", (char *)data); 00105 pbx_builtin_setvar_helper(chan, chanvar, "FAILURE"); 00106 res = failmode; 00107 } else if (res == 127) { 00108 ast_log(LOG_WARNING, "Unable to execute '%s'\n", (char *)data); 00109 pbx_builtin_setvar_helper(chan, chanvar, "FAILURE"); 00110 res = failmode; 00111 } else { 00112 if (res < 0) 00113 res = 0; 00114 if (option_priority_jumping && res) 00115 ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101); 00116 00117 if (res != 0) 00118 pbx_builtin_setvar_helper(chan, chanvar, "APPERROR"); 00119 else 00120 pbx_builtin_setvar_helper(chan, chanvar, "SUCCESS"); 00121 res = 0; 00122 } 00123 00124 LOCAL_USER_REMOVE(u); 00125 00126 return res; 00127 }
static int trysystem_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 134 of file app_system.c.
References localuser::chan, and system_exec_helper().
Referenced by load_module().
00135 { 00136 return system_exec_helper(chan, data, 0); 00137 }
int unload_module | ( | void | ) |
Cleanup all module structures, sockets, etc.
This is called at exit. Any registrations and memory allocations need to be unregistered and free'd here. Nothing else will do these for you (until exit).
Definition at line 139 of file app_system.c.
References ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS.
00140 { 00141 int res; 00142 00143 res = ast_unregister_application(app); 00144 res |= ast_unregister_application(app2); 00145 00146 STANDARD_HANGUP_LOCALUSERS; 00147 00148 return res; 00149 }
int usecount | ( | void | ) |
Provides a usecount.
This function will be called by various parts of asterisk. Basically, all it has to do is to return a usecount when called. You will need to maintain your usecount within the module somewhere. The usecount should be how many channels provided by this module are in use.
Definition at line 166 of file app_system.c.
References STANDARD_USECOUNT.
00167 { 00168 int res; 00169 STANDARD_USECOUNT(res); 00170 return res; 00171 }
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.
Definition at line 86 of file app_system.c.
Definition at line 84 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.
char* tdesc = "Generic System() application" [static] |
Definition at line 45 of file app_system.c.