Tue Aug 24 20:34:56 2010

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"
Include dependency graph for app_readfile.c:

Go to the source code of this file.

Functions

 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Stores output of file into a variable")
static int load_module (void)
static int readfile_exec (struct ast_channel *chan, void *data)
static int unload_module (void)

Variables

static char * app_readfile = "ReadFile"

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

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Stores output of file into a variable"   
)
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,
void *  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(), s, 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

char* app_readfile = "ReadFile" [static]

Definition at line 68 of file app_readfile.c.


Generated on 24 Aug 2010 for Asterisk - the Open Source PBX by  doxygen 1.6.1