Asterisk - The Open Source Telephony Project GIT-master-a63eec2
Loading...
Searching...
No Matches
Functions | Variables
app_system.c File Reference

Execute arbitrary system commands. More...

#include "asterisk.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/app.h"
#include "asterisk/channel.h"
#include "asterisk/strings.h"
#include "asterisk/threadstorage.h"
Include dependency graph for app_system.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
 AST_THREADSTORAGE_CUSTOM_SCOPE (buf_buf, NULL, ast_free_ptr, static)
 
static int load_module (void)
 
static int system_exec (struct ast_channel *chan, const char *data)
 
static int system_exec_helper (struct ast_channel *chan, const char *data, int failmode)
 
static int trysystem_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 = "Generic System() application" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static char * app = "System"
 
static char * app2 = "TrySystem"
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static char * chanvar = "SYSTEMSTATUS"
 

Detailed Description

Execute arbitrary system commands.

Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file app_system.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 200 of file app_system.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 200 of file app_system.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 200 of file app_system.c.

◆ AST_THREADSTORAGE_CUSTOM_SCOPE()

AST_THREADSTORAGE_CUSTOM_SCOPE ( buf_buf  ,
NULL  ,
ast_free_ptr  ,
static   
)

◆ load_module()

static int load_module ( void  )
static

Definition at line 190 of file app_system.c.

191{
192 int res;
193
196
197 return res;
198}
static int system_exec(struct ast_channel *chan, const char *data)
Definition app_system.c:170
static char * app2
Definition app_system.c:117
static char * app
Definition app_system.c:115
static int trysystem_exec(struct ast_channel *chan, const char *data)
Definition app_system.c:175
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition module.h:640

References app, app2, ast_register_application_xml, system_exec(), and trysystem_exec().

◆ system_exec()

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

Definition at line 170 of file app_system.c.

171{
172 return system_exec_helper(chan, data, -1);
173}
static int system_exec_helper(struct ast_channel *chan, const char *data, int failmode)
Definition app_system.c:121

References system_exec_helper().

Referenced by load_module().

◆ system_exec_helper()

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

Definition at line 121 of file app_system.c.

122{
123 int res = 0;
124 struct ast_str *buf = ast_str_thread_get(&buf_buf, 16);
125 char *cbuf;
126
127 if (ast_strlen_zero(data)) {
128 ast_log(LOG_WARNING, "System requires an argument(command)\n");
129 pbx_builtin_setvar_helper(chan, chanvar, "FAILURE");
130 return failmode;
131 }
132
134
135 /* Do our thing here */
136 ast_str_get_encoded_str(&buf, 0, (char *) data);
137 cbuf = ast_str_buffer(buf);
138
139 if (strchr("\"'", cbuf[0]) && cbuf[ast_str_strlen(buf) - 1] == cbuf[0]) {
140 cbuf[ast_str_strlen(buf) - 1] = '\0';
141 cbuf++;
142 ast_log(LOG_NOTICE, "It is not necessary to quote the argument to the System application.\n");
143 }
144
145 res = ast_safe_system(cbuf);
146
147 if ((res < 0) && (errno != ECHILD)) {
148 ast_log(LOG_WARNING, "Unable to execute '%s'\n", (char *)data);
149 pbx_builtin_setvar_helper(chan, chanvar, "FAILURE");
150 res = failmode;
151 } else if (res == 127) {
152 ast_log(LOG_WARNING, "Unable to execute '%s'\n", (char *)data);
153 pbx_builtin_setvar_helper(chan, chanvar, "FAILURE");
154 res = failmode;
155 } else {
156 if (res < 0)
157 res = 0;
158 if (res != 0)
159 pbx_builtin_setvar_helper(chan, chanvar, "APPERROR");
160 else
161 pbx_builtin_setvar_helper(chan, chanvar, "SUCCESS");
162 res = 0;
163 }
164
166
167 return res;
168}
#define ast_log
Definition astobj2.c:42
int ast_autoservice_stop(struct ast_channel *chan)
Stop servicing a channel for us...
int ast_autoservice_start(struct ast_channel *chan)
Automatically service a channel for us...
char buf[BUFSIZE]
Definition eagi_proxy.c:66
int ast_str_get_encoded_str(struct ast_str **str, int maxlen, const char *stream)
Decode a stream of encoded control or extended ASCII characters.
Definition main/app.c:3175
int ast_safe_system(const char *s)
Safely spawn an OS shell command while closing file descriptors.
Definition extconf.c:827
#define LOG_NOTICE
#define LOG_WARNING
int errno
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.
size_t attribute_pure ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition strings.h:730
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition strings.h:761
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Definition strings.h:909
Support for dynamic strings.
Definition strings.h:623
structure for queuing ARI channel variable setting
Definition control.c:726

References ast_autoservice_start(), ast_autoservice_stop(), ast_log, ast_safe_system(), ast_str_buffer(), ast_str_get_encoded_str(), ast_str_strlen(), ast_str_thread_get(), ast_strlen_zero(), buf, errno, LOG_NOTICE, LOG_WARNING, and pbx_builtin_setvar_helper().

Referenced by system_exec(), and trysystem_exec().

◆ trysystem_exec()

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

Definition at line 175 of file app_system.c.

176{
177 return system_exec_helper(chan, data, 0);
178}

References system_exec_helper().

Referenced by load_module().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 180 of file app_system.c.

181{
182 int res;
183
186
187 return res;
188}
int ast_unregister_application(const char *app)
Unregister an application.
Definition pbx_app.c:392

References app, app2, and ast_unregister_application().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Generic System() application" , .key = ASTERISK_GPL_KEY , .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 200 of file app_system.c.

◆ app

char* app = "System"
static

Definition at line 115 of file app_system.c.

Referenced by load_module(), and unload_module().

◆ app2

char* app2 = "TrySystem"
static

Definition at line 117 of file app_system.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 200 of file app_system.c.

◆ chanvar

char* chanvar = "SYSTEMSTATUS"
static

Definition at line 119 of file app_system.c.