Wed Oct 28 11:46:10 2009

Asterisk developer's documentation


func_shell.c File Reference

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"

Include dependency graph for func_shell.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
static void __unreg_module (void)
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_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Returns the output of a shell command" , .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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, }
static const struct
ast_module_info
ast_module_info = &__mod_info
static struct ast_custom_function shell_function


Detailed Description

SHELL function to return the value of a system call.

Note:
Inspiration and Guidance from Russell! Thank You!
Author:
Brandon Kruse <bkruse@digium.com>

Definition in file func_shell.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 91 of file func_shell.c.

static void __unreg_module ( void   )  [static]

Definition at line 91 of file func_shell.c.

static int load_module ( void   )  [static]

Definition at line 86 of file func_shell.c.

References ast_custom_function_register.

00087 {
00088    return ast_custom_function_register(&shell_function);
00089 }

static int shell_helper ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 38 of file func_shell.c.

References ast_autoservice_start(), ast_autoservice_stop(), ast_log(), ast_strlen_zero(), and LOG_WARNING.

00040 {
00041    if (ast_strlen_zero(data)) {
00042       ast_log(LOG_WARNING, "Missing Argument!  Example:  Set(foo=${SHELL(echo \"bar\")})\n");
00043       return -1;
00044    }
00045 
00046    if (chan)
00047       ast_autoservice_start(chan);
00048 
00049    if (len >= 1) {
00050       FILE *ptr;
00051       char plbuff[4096];
00052 
00053       ptr = popen(data, "r");
00054       while (fgets(plbuff, sizeof(plbuff), ptr)) {
00055          strncat(buf, plbuff, len - strlen(buf) - 1);
00056       }
00057       pclose(ptr);
00058    }
00059 
00060    if (chan)
00061       ast_autoservice_stop(chan);
00062 
00063    return 0;
00064 }

static int unload_module ( void   )  [static]

Definition at line 81 of file func_shell.c.

References ast_custom_function_unregister().

00082 {
00083    return ast_custom_function_unregister(&shell_function);
00084 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Returns the output of a shell command" , .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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } [static]

Definition at line 91 of file func_shell.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 91 of file func_shell.c.

Definition at line 66 of file func_shell.c.


Generated on Wed Oct 28 11:46:10 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6