Sat Aug 6 00:39:36 2011

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"

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, void *data)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, }
static char * app_readfile = "ReadFile"
static const struct ast_module_infoast_module_info = &__mod_info
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

static void __reg_module ( void   )  [static]

Definition at line 120 of file app_readfile.c.

static void __unreg_module ( void   )  [static]

Definition at line 120 of file app_readfile.c.

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, free, len(), LOG_ERROR, LOG_WARNING, pbx_builtin_setvar_helper(), and s.

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, "%30d", &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

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } [static]

Definition at line 120 of file app_readfile.c.

char* app_readfile = "ReadFile" [static]

Definition at line 45 of file app_readfile.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 120 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 Sat Aug 6 00:39:36 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7