Mon Jul 14 17:25:05 2008

Asterisk developer's documentation


app_readfile.c File Reference

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

#include "asterisk.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/options.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"
static char * readfile_descrip
static char * readfile_synopsis = "ReadFile(varname=file,length)"


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 115 of file app_readfile.c.

References ast_register_application(), and readfile_exec().

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

Definition at line 56 of file app_readfile.c.

References ast_log(), ast_module_user_add, ast_module_user_remove, ast_read_textfile(), ast_strdupa, ast_strlen_zero(), ast_module_user::chan, file, free, len, LOG_ERROR, LOG_WARNING, pbx_builtin_setvar_helper(), s, and strsep().

Referenced by load_module().

00057 {
00058    int res=0;
00059    struct ast_module_user *u;
00060    char *s, *varname=NULL, *file=NULL, *length=NULL, *returnvar=NULL;
00061    int len=0;
00062 
00063    if (ast_strlen_zero(data)) {
00064       ast_log(LOG_WARNING, "ReadFile require an argument!\n");
00065       return -1;
00066    }
00067 
00068    u = ast_module_user_add(chan);
00069 
00070    s = ast_strdupa(data);
00071 
00072    varname = strsep(&s, "=");
00073    file = strsep(&s, "|");
00074    length = s;
00075 
00076    if (!varname || !file) {
00077       ast_log(LOG_ERROR, "No file or variable specified!\n");
00078       ast_module_user_remove(u);
00079       return -1;
00080    }
00081 
00082    if (length) {
00083       if ((sscanf(length, "%d", &len) != 1) || (len < 0)) {
00084          ast_log(LOG_WARNING, "%s is not a positive number, defaulting length to max\n", length);
00085          len = 0;
00086       }
00087    }
00088 
00089    if ((returnvar = ast_read_textfile(file))) {
00090       if (len > 0) {
00091          if (len < strlen(returnvar))
00092             returnvar[len]='\0';
00093          else
00094             ast_log(LOG_WARNING, "%s is longer than %d, and %d \n", file, len, (int)strlen(returnvar));
00095       }
00096       pbx_builtin_setvar_helper(chan, varname, returnvar);
00097       free(returnvar);
00098    }
00099    ast_module_user_remove(u);
00100    return res;
00101 }

static int unload_module ( void   )  [static]

Definition at line 104 of file app_readfile.c.

References ast_module_user_hangup_all, and ast_unregister_application().

00105 {
00106    int res;
00107 
00108    res = ast_unregister_application(app_readfile);
00109    
00110    ast_module_user_hangup_all();
00111 
00112    return res; 
00113 }


Variable Documentation

char* app_readfile = "ReadFile" [static]

Definition at line 45 of file app_readfile.c.

char* readfile_descrip [static]

Initial value:

"ReadFile(varname=file,length)\n"
"  Varname - Result stored here.\n"
"  File - The name of the file to read.\n"
"  Length - Maximum number of characters to capture.\n"

Definition at line 49 of file app_readfile.c.

char* readfile_synopsis = "ReadFile(varname=file,length)" [static]

Definition at line 47 of file app_readfile.c.


Generated on Mon Jul 14 17:25:05 2008 for Asterisk - the Open Source PBX by  doxygen 1.5.1