Mon Jun 27 16:50:59 2011

Asterisk developer's documentation


app_readfile.c File Reference

ReadFile application -- Reads in a File for you. More...

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

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 readfile_exec (struct ast_channel *chan, const char *data)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Stores output of file into a variable" , .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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static char * app_readfile = "ReadFile"
static struct ast_module_infoast_module_info = &__mod_info


Detailed Description

ReadFile application -- Reads in a File for you.

Author:
Matt O'Gorman <mogorman@digium.com>

Definition in file app_readfile.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 128 of file app_readfile.c.

static void __unreg_module ( void   )  [static]

Definition at line 128 of file app_readfile.c.

static int load_module ( void   )  [static]

Definition at line 123 of file app_readfile.c.

References ast_register_application_xml, and readfile_exec().

static int readfile_exec ( struct ast_channel chan,
const char *  data 
) [static]

Definition at line 70 of file app_readfile.c.

References ast_free, ast_log(), ast_read_textfile(), ast_strdupa, ast_strlen_zero(), len(), LOG_ERROR, LOG_WARNING, pbx_builtin_setvar_helper(), and strsep().

Referenced by load_module().

00071 {
00072    int res=0;
00073    char *s, *varname=NULL, *file=NULL, *length=NULL, *returnvar=NULL;
00074    int len=0;
00075    static int deprecation_warning = 0;
00076 
00077    if (ast_strlen_zero(data)) {
00078       ast_log(LOG_WARNING, "ReadFile require an argument!\n");
00079       return -1;
00080    }
00081 
00082    s = ast_strdupa(data);
00083 
00084    varname = strsep(&s, "=");
00085    file = strsep(&s, ",");
00086    length = s;
00087 
00088    if (deprecation_warning++ % 10 == 0)
00089       ast_log(LOG_WARNING, "ReadFile has been deprecated in favor of Set(%s=${FILE(%s,0,%s)})\n", varname, file, length);
00090 
00091    if (!varname || !file) {
00092       ast_log(LOG_ERROR, "No file or variable specified!\n");
00093       return -1;
00094    }
00095 
00096    if (length) {
00097       if ((sscanf(length, "%30d", &len) != 1) || (len < 0)) {
00098          ast_log(LOG_WARNING, "%s is not a positive number, defaulting length to max\n", length);
00099          len = 0;
00100       }
00101    }
00102 
00103    if ((returnvar = ast_read_textfile(file))) {
00104       if (len > 0) {
00105          if (len < strlen(returnvar))
00106             returnvar[len]='\0';
00107          else
00108             ast_log(LOG_WARNING, "%s is longer than %d, and %d \n", file, len, (int)strlen(returnvar));
00109       }
00110       pbx_builtin_setvar_helper(chan, varname, returnvar);
00111       ast_free(returnvar);
00112    }
00113 
00114    return res;
00115 }

static int unload_module ( void   )  [static]

Definition at line 118 of file app_readfile.c.

References ast_unregister_application().

00119 {
00120    return ast_unregister_application(app_readfile);
00121 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Stores output of file into a variable" , .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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static]

Definition at line 128 of file app_readfile.c.

char* app_readfile = "ReadFile" [static]

Definition at line 68 of file app_readfile.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 128 of file app_readfile.c.


Generated on Mon Jun 27 16:50:59 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7