#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, void *data) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } |
static char * | app_readfile = "ReadFile" |
static struct ast_module_info * | ast_module_info = &__mod_info |
static char * | readfile_descrip |
static char * | readfile_synopsis = "Read the contents of a text file into a channel variable" |
Definition in file app_readfile.c.
static void __reg_module | ( | void | ) | [static] |
Definition at line 107 of file app_readfile.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 107 of file app_readfile.c.
static int load_module | ( | void | ) | [static] |
Definition at line 102 of file app_readfile.c.
References ast_register_application, and readfile_exec().
00103 { 00104 return ast_register_application(app_readfile, readfile_exec, readfile_synopsis, readfile_descrip); 00105 }
static int readfile_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 49 of file app_readfile.c.
References ast_free, ast_log(), ast_read_textfile(), ast_strdupa, ast_strlen_zero(), chan, len(), LOG_ERROR, LOG_WARNING, pbx_builtin_setvar_helper(), s, and strsep().
Referenced by load_module().
00050 { 00051 int res=0; 00052 char *s, *varname=NULL, *file=NULL, *length=NULL, *returnvar=NULL; 00053 int len=0; 00054 static int deprecation_warning = 0; 00055 00056 if (ast_strlen_zero(data)) { 00057 ast_log(LOG_WARNING, "ReadFile require an argument!\n"); 00058 return -1; 00059 } 00060 00061 s = ast_strdupa(data); 00062 00063 varname = strsep(&s, "="); 00064 file = strsep(&s, ","); 00065 length = s; 00066 00067 if (deprecation_warning++ % 10 == 0) 00068 ast_log(LOG_WARNING, "ReadFile has been deprecated in favor of Set(%s=${FILE(%s,0,%s)})\n", varname, file, length); 00069 00070 if (!varname || !file) { 00071 ast_log(LOG_ERROR, "No file or variable specified!\n"); 00072 return -1; 00073 } 00074 00075 if (length) { 00076 if ((sscanf(length, "%d", &len) != 1) || (len < 0)) { 00077 ast_log(LOG_WARNING, "%s is not a positive number, defaulting length to max\n", length); 00078 len = 0; 00079 } 00080 } 00081 00082 if ((returnvar = ast_read_textfile(file))) { 00083 if (len > 0) { 00084 if (len < strlen(returnvar)) 00085 returnvar[len]='\0'; 00086 else 00087 ast_log(LOG_WARNING, "%s is longer than %d, and %d \n", file, len, (int)strlen(returnvar)); 00088 } 00089 pbx_builtin_setvar_helper(chan, varname, returnvar); 00090 ast_free(returnvar); 00091 } 00092 00093 return res; 00094 }
static int unload_module | ( | void | ) | [static] |
Definition at line 97 of file app_readfile.c.
References ast_unregister_application().
00098 { 00099 return ast_unregister_application(app_readfile); 00100 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 107 of file app_readfile.c.
char* app_readfile = "ReadFile" [static] |
Definition at line 38 of file app_readfile.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 107 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 42 of file app_readfile.c.
char* readfile_synopsis = "Read the contents of a text file into a channel variable" [static] |
Definition at line 40 of file app_readfile.c.