Fri Aug 17 00:17:23 2018

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

 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, const char *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 128 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 75 of file app_readfile.c.

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

Referenced by load_module().

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

static int unload_module ( void   )  [static]

Definition at line 123 of file app_readfile.c.

References ast_unregister_application().

00124 {
00125    return ast_unregister_application(app_readfile);
00126 }


Variable Documentation

char* app_readfile = "ReadFile" [static]

Definition at line 73 of file app_readfile.c.


Generated on 17 Aug 2018 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1