Fri Aug 24 02:23:03 2007

Asterisk developer's documentation


app_system.c File Reference

Execute arbitrary system commands. More...

#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"


Detailed Description

Execute arbitrary system commands.

Author:
Mark Spencer <markster@digium.com>

Definition in file app_system.c.


Function Documentation

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Generic System() application"   
)

static int load_module ( void   )  [static]

Definition at line 148 of file app_system.c.

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

00149 {
00150    int res;
00151 
00152    res = ast_register_application(app2, trysystem_exec, synopsis2, descrip2);
00153    res |= ast_register_application(app, system_exec, synopsis, descrip);
00154 
00155    return res;
00156 }

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

Definition at line 126 of file app_system.c.

References ast_module_user::chan, and system_exec_helper().

Referenced by load_module().

00127 {
00128    return system_exec_helper(chan, data, -1);
00129 }

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_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, 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    /* Do our thing here */
00099    res = ast_safe_system((char *)data);
00100    if ((res < 0) && (errno != ECHILD)) {
00101       ast_log(LOG_WARNING, "Unable to execute '%s'\n", (char *)data);
00102       pbx_builtin_setvar_helper(chan, chanvar, "FAILURE");
00103       res = failmode;
00104    } else if (res == 127) {
00105       ast_log(LOG_WARNING, "Unable to execute '%s'\n", (char *)data);
00106       pbx_builtin_setvar_helper(chan, chanvar, "FAILURE");
00107       res = failmode;
00108    } else {
00109       if (res < 0) 
00110          res = 0;
00111       if (ast_opt_priority_jumping && res)
00112          ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
00113 
00114       if (res != 0)
00115          pbx_builtin_setvar_helper(chan, chanvar, "APPERROR");
00116       else
00117          pbx_builtin_setvar_helper(chan, chanvar, "SUCCESS");
00118       res = 0;
00119    } 
00120 
00121    ast_module_user_remove(u);
00122 
00123    return res;
00124 }

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

Definition at line 131 of file app_system.c.

References ast_module_user::chan, and system_exec_helper().

Referenced by load_module().

00132 {
00133    return system_exec_helper(chan, data, 0);
00134 }

static int unload_module ( void   )  [static]

Definition at line 136 of file app_system.c.

References ast_module_user_hangup_all, and ast_unregister_application().

00137 {
00138    int res;
00139 
00140    res = ast_unregister_application(app);
00141    res |= ast_unregister_application(app2);
00142    
00143    ast_module_user_hangup_all();
00144 
00145    return res;
00146 }


Variable Documentation

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.


Generated on Fri Aug 24 02:23:04 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.1