Thu Jul 9 13:40:49 2009

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 = "068e67f60f50dd9ee86464c05884a49d" , .load = load_module, .unload = unload_module, }
static char * app = "System"
static char * app2 = "TrySystem"
static const 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 136 of file app_system.c.

static void __unreg_module ( void   )  [static]

Definition at line 136 of file app_system.c.

static int load_module ( void   )  [static]

Definition at line 126 of file app_system.c.

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

00127 {
00128    int res;
00129 
00130    res = ast_register_application(app2, trysystem_exec, synopsis2, descrip2);
00131    res |= ast_register_application(app, system_exec, synopsis, descrip);
00132 
00133    return res;
00134 }

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

Definition at line 106 of file app_system.c.

References chan, and system_exec_helper().

Referenced by load_module().

00107 {
00108    return system_exec_helper(chan, data, -1);
00109 }

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_thread_get(), ast_strlen_zero(), buf, buf_buf, chan, errno, 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    
00071    if (ast_strlen_zero(data)) {
00072       ast_log(LOG_WARNING, "System requires an argument(command)\n");
00073       pbx_builtin_setvar_helper(chan, chanvar, "FAILURE");
00074       return failmode;
00075    }
00076 
00077    ast_autoservice_start(chan);
00078 
00079    /* Do our thing here */
00080    ast_str_get_encoded_str(&buf, 0, (char *) data);
00081    res = ast_safe_system(ast_str_buffer(buf));
00082 
00083    if ((res < 0) && (errno != ECHILD)) {
00084       ast_log(LOG_WARNING, "Unable to execute '%s'\n", (char *)data);
00085       pbx_builtin_setvar_helper(chan, chanvar, "FAILURE");
00086       res = failmode;
00087    } else if (res == 127) {
00088       ast_log(LOG_WARNING, "Unable to execute '%s'\n", (char *)data);
00089       pbx_builtin_setvar_helper(chan, chanvar, "FAILURE");
00090       res = failmode;
00091    } else {
00092       if (res < 0) 
00093          res = 0;
00094       if (res != 0)
00095          pbx_builtin_setvar_helper(chan, chanvar, "APPERROR");
00096       else
00097          pbx_builtin_setvar_helper(chan, chanvar, "SUCCESS");
00098       res = 0;
00099    } 
00100 
00101    ast_autoservice_stop(chan);
00102 
00103    return res;
00104 }

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

Definition at line 111 of file app_system.c.

References chan, and system_exec_helper().

Referenced by load_module().

00112 {
00113    return system_exec_helper(chan, data, 0);
00114 }

static int unload_module ( void   )  [static]

Definition at line 116 of file app_system.c.

References ast_unregister_application().

00117 {
00118    int res;
00119 
00120    res = ast_unregister_application(app);
00121    res |= ast_unregister_application(app2);
00122 
00123    return res;
00124 }


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 = "068e67f60f50dd9ee86464c05884a49d" , .load = load_module, .unload = unload_module, } [static]

Definition at line 136 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.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 136 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 Thu Jul 9 13:40:49 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7