Wed Jan 8 2020 09:49:55

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

static void __reg_module (void)
 
static void __unreg_module (void)
 
static int load_module (void)
 
static int readfile_exec (struct ast_channel *chan, const char *data)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
 
static char * app_readfile = "ReadFile"
 
static struct ast_module_infoast_module_info = &__mod_info
 

Detailed Description

ReadFile application – Reads in a File for you.

Author
Matt O'Gorman mogor.nosp@m.man@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file app_readfile.c.

Function Documentation

static void __reg_module ( void  )
static

Definition at line 133 of file app_readfile.c.

static void __unreg_module ( void  )
static

Definition at line 133 of file app_readfile.c.

static int load_module ( void  )
static

Definition at line 128 of file app_readfile.c.

References ast_register_application_xml, and readfile_exec().

129 {
131 }
static char * app_readfile
Definition: app_readfile.c:73
static int readfile_exec(struct ast_channel *chan, const char *data)
Definition: app_readfile.c:75
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
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, pbx_builtin_setvar_helper(), and strsep().

Referenced by load_module().

76 {
77  int res=0;
78  char *s, *varname=NULL, *file=NULL, *length=NULL, *returnvar=NULL;
79  int len=0;
80  static int deprecation_warning = 0;
81 
82  if (ast_strlen_zero(data)) {
83  ast_log(LOG_WARNING, "ReadFile require an argument!\n");
84  return -1;
85  }
86 
87  s = ast_strdupa(data);
88 
89  varname = strsep(&s, "=");
90  file = strsep(&s, ",");
91  length = s;
92 
93  if (deprecation_warning++ % 10 == 0)
94  ast_log(LOG_WARNING, "ReadFile has been deprecated in favor of Set(%s=${FILE(%s,0,%s)})\n", varname, file, length);
95 
96  if (!varname || !file) {
97  ast_log(LOG_ERROR, "No file or variable specified!\n");
98  return -1;
99  }
100 
101  if (length) {
102  if ((sscanf(length, "%30d", &len) != 1) || (len < 0)) {
103  ast_log(LOG_WARNING, "%s is not a positive number, defaulting length to max\n", length);
104  len = 0;
105  }
106  }
107 
108  if ((returnvar = ast_read_textfile(file))) {
109  if (len > 0) {
110  if (len < strlen(returnvar))
111  returnvar[len]='\0';
112  else
113  ast_log(LOG_WARNING, "%s is longer than %d, and %d \n", file, len, (int)strlen(returnvar));
114  }
115  pbx_builtin_setvar_helper(chan, varname, returnvar);
116  ast_free(returnvar);
117  }
118 
119  return res;
120 }
char * strsep(char **str, const char *delims)
#define LOG_WARNING
Definition: logger.h:144
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
#define LOG_ERROR
Definition: logger.h:155
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ast_free(a)
Definition: astmm.h:97
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
Definition: pbx.c:10546
char * ast_read_textfile(const char *file)
Read a file into asterisk.
Definition: app.c:1987
static int unload_module ( void  )
static

Definition at line 123 of file app_readfile.c.

References ast_unregister_application().

124 {
126 }
static char * app_readfile
Definition: app_readfile.c:73
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705

Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static

Definition at line 133 of file app_readfile.c.

char* app_readfile = "ReadFile"
static

Definition at line 73 of file app_readfile.c.

Definition at line 133 of file app_readfile.c.