#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
Go to the source code of this file.
Functions | |
AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Collects the output generated by a command executed by the system shell") | |
static int | load_module (void) |
static int | shell_helper (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
static int | unload_module (void) |
Variables | |
static struct ast_custom_function | shell_function |
SHELL function to return the output generated by a command issued to the system shell.
Definition in file func_shell.c.
AST_MODULE_INFO_STANDARD | ( | ASTERISK_GPL_KEY | , | |
"Collects the output generated by a command executed by the system shell" | ||||
) |
static int load_module | ( | void | ) | [static] |
Definition at line 116 of file func_shell.c.
References AST_CFE_READ, and ast_custom_function_register_escalating.
00117 { 00118 return ast_custom_function_register_escalating(&shell_function, AST_CFE_READ); 00119 }
static int shell_helper | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | data, | |||
char * | buf, | |||
size_t | len | |||
) | [static] |
Definition at line 42 of file func_shell.c.
References ast_autoservice_start(), ast_autoservice_stop(), ast_log(), ast_strlen_zero(), and LOG_WARNING.
00044 { 00045 int res = 0; 00046 00047 if (ast_strlen_zero(data)) { 00048 ast_log(LOG_WARNING, "Missing Argument! Example: Set(foo=${SHELL(echo \"bar\")})\n"); 00049 return -1; 00050 } 00051 00052 if (chan) { 00053 ast_autoservice_start(chan); 00054 } 00055 00056 if (len >= 1) { 00057 FILE *ptr; 00058 char plbuff[4096]; 00059 00060 ptr = popen(data, "r"); 00061 if (ptr) { 00062 while (fgets(plbuff, sizeof(plbuff), ptr)) { 00063 strncat(buf, plbuff, len - strlen(buf) - 1); 00064 } 00065 pclose(ptr); 00066 } else { 00067 ast_log(LOG_WARNING, "Failed to execute shell command '%s'\n", data); 00068 res = -1; 00069 } 00070 } 00071 00072 if (chan) { 00073 ast_autoservice_stop(chan); 00074 } 00075 00076 return res; 00077 }
static int unload_module | ( | void | ) | [static] |
Definition at line 111 of file func_shell.c.
References ast_custom_function_unregister().
00112 { 00113 return ast_custom_function_unregister(&shell_function); 00114 }
struct ast_custom_function shell_function [static] |
{ .name = "SHELL", .read = shell_helper, }
Definition at line 106 of file func_shell.c.