Wed Aug 18 22:34:02 2010

Asterisk developer's documentation


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"

Go to the source code of this file.

Functions

static void __init_buf_buf (void)
static void __reg_module (void)
static void __unreg_module (void)
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 struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Generic System() application" , .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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, }
static char * app = "System"
static char * app2 = "TrySystem"
static struct ast_module_infoast_module_info = &__mod_info
static struct ast_threadstorage buf_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_buf_buf , .custom_init = NULL , }
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"


Detailed Description

Execute arbitrary system commands.

Author:
Mark Spencer <markster@digium.com>

Definition in file app_system.c.


Function Documentation

static void __init_buf_buf ( void   )  [static]

Definition at line 39 of file app_system.c.

00052 : Executes a command  by  using  system(). If the command\n"

static void __reg_module ( void   )  [static]

Definition at line 145 of file app_system.c.

static void __unreg_module ( void   )  [static]

Definition at line 145 of file app_system.c.

static int load_module ( void   )  [static]

Definition at line 135 of file app_system.c.

References ast_register_application, system_exec(), and trysystem_exec().

00136 {
00137    int res;
00138 
00139    res = ast_register_application(app2, trysystem_exec, synopsis2, descrip2);
00140    res |= ast_register_application(app, system_exec, synopsis, descrip);
00141 
00142    return res;
00143 }

static int system_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 115 of file app_system.c.

References chan, and system_exec_helper().

Referenced by load_module().

00116 {
00117    return system_exec_helper(chan, data, -1);
00118 }

static int system_exec_helper ( struct ast_channel chan,
void *  data,
int  failmode 
) [static]

Definition at line 66 of file app_system.c.

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, buf_buf, chan, errno, LOG_NOTICE, LOG_WARNING, and pbx_builtin_setvar_helper().

Referenced by system_exec(), and trysystem_exec().

00067 {
00068    int res = 0;
00069    struct ast_str *buf = ast_str_thread_get(&buf_buf, 16);
00070    char *cbuf;
00071 
00072    if (ast_strlen_zero(data)) {
00073       ast_log(LOG_WARNING, "System requires an argument(command)\n");
00074       pbx_builtin_setvar_helper(chan, chanvar, "FAILURE");
00075       return failmode;
00076    }
00077 
00078    ast_autoservice_start(chan);
00079 
00080    /* Do our thing here */
00081    ast_str_get_encoded_str(&buf, 0, (char *) data);
00082    cbuf = ast_str_buffer(buf);
00083 
00084    if (strchr("\"'", cbuf[0]) && cbuf[ast_str_strlen(buf) - 1] == cbuf[0]) {
00085       cbuf[ast_str_strlen(buf) - 1] = '\0';
00086       cbuf++;
00087       ast_log(LOG_NOTICE, "It is not necessary to quote the argument to the System application.\n");
00088    }
00089 
00090    res = ast_safe_system(cbuf);
00091 
00092    if ((res < 0) && (errno != ECHILD)) {
00093       ast_log(LOG_WARNING, "Unable to execute '%s'\n", (char *)data);
00094       pbx_builtin_setvar_helper(chan, chanvar, "FAILURE");
00095       res = failmode;
00096    } else if (res == 127) {
00097       ast_log(LOG_WARNING, "Unable to execute '%s'\n", (char *)data);
00098       pbx_builtin_setvar_helper(chan, chanvar, "FAILURE");
00099       res = failmode;
00100    } else {
00101       if (res < 0) 
00102          res = 0;
00103       if (res != 0)
00104          pbx_builtin_setvar_helper(chan, chanvar, "APPERROR");
00105       else
00106          pbx_builtin_setvar_helper(chan, chanvar, "SUCCESS");
00107       res = 0;
00108    } 
00109 
00110    ast_autoservice_stop(chan);
00111 
00112    return res;
00113 }

static int trysystem_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 120 of file app_system.c.

References chan, and system_exec_helper().

Referenced by load_module().

00121 {
00122    return system_exec_helper(chan, data, 0);
00123 }

static int unload_module ( void   )  [static]

Definition at line 125 of file app_system.c.

References ast_unregister_application().

00126 {
00127    int res;
00128 
00129    res = ast_unregister_application(app);
00130    res |= ast_unregister_application(app2);
00131 
00132    return res;
00133 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Generic System() application" , .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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } [static]

Definition at line 145 of file app_system.c.

char* app = "System" [static]

Definition at line 41 of file app_system.c.

char* app2 = "TrySystem" [static]

Definition at line 43 of file app_system.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 145 of file app_system.c.

struct ast_threadstorage buf_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_buf_buf , .custom_init = NULL , } [static]

Definition at line 39 of file app_system.c.

Referenced by system_exec_helper().

char* chanvar = "SYSTEMSTATUS" [static]

Definition at line 49 of file app_system.c.

Referenced by function_sippeer(), and load_config().

char* descrip [static]

Definition at line 51 of file app_system.c.

char* descrip2 [static]

Definition at line 58 of file app_system.c.

char* synopsis = "Execute a system command" [static]

Definition at line 45 of file app_system.c.

char* synopsis2 = "Try executing a system command" [static]

Definition at line 47 of file app_system.c.


Generated on Wed Aug 18 22:34:02 2010 for Asterisk - the Open Source PBX by  doxygen 1.4.7