Mon Mar 20 08:20:16 2006

Asterisk developer's documentation


Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

app_system.c File Reference

Execute arbitrary system commands. More...

#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.
int system_exec (struct ast_channel *chan, void *data)
int system_exec_helper (struct ast_channel *chan, void *data, int failmode)
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

char * app = "System"
char * app2 = "TrySystem"
char * chanvar = "SYSTEMSTATUS"
char * descrip
char * descrip2
 LOCAL_USER_DECL
 STANDARD_LOCAL_USER
char * synopsis = "Execute a system command"
char * synopsis2 = "Try executing a system command"
char * tdesc = "Generic System() application"


Detailed Description

Execute arbitrary system commands.

Definition in file app_system.c.


Function Documentation

char* description void   ) 
 

Provides a description of the module.

Returns:
a short description of your 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;
 }

Returns:
ASTERISK_GPL_KEY

Definition at line 173 of file app_system.c.

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.

Returns:
int Always 0.

Definition at line 151 of file app_system.c.

References app, app2, ast_register_application(), descrip, descrip2, synopsis, synopsis2, 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 }

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

Definition at line 129 of file app_system.c.

References system_exec_helper().

Referenced by load_module().

00130 {
00131    return system_exec_helper(chan, data, -1);
00132 }

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(), chanvar, ast_channel::context, ast_channel::exten, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_WARNING, option_priority_jumping, pbx_builtin_setvar_helper(), and ast_channel::priority.

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 }

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

Definition at line 134 of file app_system.c.

References 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).

Returns:
Zero on success, or non-zero on error.

Definition at line 139 of file app_system.c.

References app, app2, and ast_unregister_application().

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.

Returns:
The module's usecount.

Definition at line 166 of file app_system.c.

References STANDARD_USECOUNT.

00167 {
00168    int res;
00169    STANDARD_USECOUNT(res);
00170    return res;
00171 }


Variable Documentation

char* app = "System" [static]
 

Definition at line 47 of file app_system.c.

Referenced by load_module(), and unload_module().

char* app2 = "TrySystem" [static]
 

Definition at line 49 of file app_system.c.

Referenced by load_module(), and unload_module().

char* chanvar = "SYSTEMSTATUS" [static]
 

Definition at line 55 of file app_system.c.

Referenced by system_exec_helper().

char* descrip [static]
 

Definition at line 57 of file app_system.c.

Referenced by load_module().

char* descrip2 [static]
 

Definition at line 71 of file app_system.c.

Referenced by load_module().

LOCAL_USER_DECL
 

Definition at line 86 of file app_system.c.

STANDARD_LOCAL_USER
 

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.

Referenced by load_module().

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

Definition at line 53 of file app_system.c.

Referenced by load_module().

char* tdesc = "Generic System() application" [static]
 

Definition at line 45 of file app_system.c.


Generated on Mon Mar 20 08:20:16 2006 for Asterisk - the Open Source PBX by  doxygen 1.3.9.1