#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/app.h"
#include "asterisk/module.h"
#include "asterisk/translate.h"
#include "asterisk/options.h"
#include "asterisk/utils.h"
#include "asterisk/indications.h"
Go to the source code of this file.
Defines | |
#define | ast_next_data(instr, ptr, delim) if((ptr=strchr(instr,delim))) { *(ptr) = '\0' ; ptr++;} |
Enumerations | |
enum | { OPT_SKIP = (1 << 0), OPT_INDICATION = (1 << 1), OPT_NOANSWER = (1 << 2) } |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | load_module (void) |
static int | read_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 = "Read Variable Application" , .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 = "Read" |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static char * | descrip |
static struct ast_app_option | read_app_options [128] = { [ 's' ] = { .flag = OPT_SKIP }, [ 'i' ] = { .flag = OPT_INDICATION }, [ 'n' ] = { .flag = OPT_NOANSWER },} |
enum { ... } | read_option_flags |
static char * | synopsis = "Read a variable" |
Definition in file app_read.c.
#define ast_next_data | ( | instr, | |||
ptr, | |||||
delim | ) | if((ptr=strchr(instr,delim))) { *(ptr) = '\0' ; ptr++;} |
Definition at line 89 of file app_read.c.
anonymous enum |
Definition at line 48 of file app_read.c.
00048 { 00049 OPT_SKIP = (1 << 0), 00050 OPT_INDICATION = (1 << 1), 00051 OPT_NOANSWER = (1 << 2), 00052 } read_option_flags;
static void __reg_module | ( | void | ) | [static] |
Definition at line 243 of file app_read.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 243 of file app_read.c.
static int load_module | ( | void | ) | [static] |
Definition at line 238 of file app_read.c.
References ast_register_application(), and read_exec().
00239 { 00240 return ast_register_application(app, read_exec, synopsis, descrip); 00241 }
static int read_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 91 of file app_read.c.
References ast_channel::_state, ast_answer(), AST_APP_ARG, ast_app_getdata(), ast_app_parse_options(), AST_DECLARE_APP_ARGS, ast_get_indication_tone(), ast_log(), ast_module_user_add, ast_module_user_remove, ast_playtones_start(), ast_playtones_stop(), AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_stopstream(), ast_strdupa, ast_strlen_zero(), ast_test_flag, ast_verbose(), ast_waitfordigit(), tone_zone_sound::data, ast_flags::flags, LOG_WARNING, OPT_INDICATION, OPT_NOANSWER, OPT_SKIP, option_verbose, pbx_builtin_setvar_helper(), VERBOSE_PREFIX_3, and ast_channel::zone.
Referenced by load_module().
00092 { 00093 int res = 0; 00094 struct ast_module_user *u; 00095 char tmp[256] = ""; 00096 int maxdigits = 255; 00097 int tries = 1, to = 0, x = 0; 00098 char *argcopy = NULL; 00099 struct tone_zone_sound *ts; 00100 struct ast_flags flags = {0}; 00101 00102 AST_DECLARE_APP_ARGS(arglist, 00103 AST_APP_ARG(variable); 00104 AST_APP_ARG(filename); 00105 AST_APP_ARG(maxdigits); 00106 AST_APP_ARG(options); 00107 AST_APP_ARG(attempts); 00108 AST_APP_ARG(timeout); 00109 ); 00110 00111 if (ast_strlen_zero(data)) { 00112 ast_log(LOG_WARNING, "Read requires an argument (variable)\n"); 00113 return -1; 00114 } 00115 00116 u = ast_module_user_add(chan); 00117 00118 argcopy = ast_strdupa(data); 00119 00120 AST_STANDARD_APP_ARGS(arglist, argcopy); 00121 00122 if (!ast_strlen_zero(arglist.options)) { 00123 ast_app_parse_options(read_app_options, &flags, NULL, arglist.options); 00124 } 00125 00126 if (!ast_strlen_zero(arglist.attempts)) { 00127 tries = atoi(arglist.attempts); 00128 if (tries <= 0) 00129 tries = 1; 00130 } 00131 00132 if (!ast_strlen_zero(arglist.timeout)) { 00133 to = atoi(arglist.timeout); 00134 if (to <= 0) 00135 to = 0; 00136 else 00137 to *= 1000; 00138 } 00139 00140 if (ast_strlen_zero(arglist.filename)) { 00141 arglist.filename = NULL; 00142 } 00143 if (!ast_strlen_zero(arglist.maxdigits)) { 00144 maxdigits = atoi(arglist.maxdigits); 00145 if ((maxdigits<1) || (maxdigits>255)) { 00146 maxdigits = 255; 00147 } else if (option_verbose > 2) 00148 ast_verbose(VERBOSE_PREFIX_3 "Accepting a maximum of %d digits.\n", maxdigits); 00149 } 00150 if (ast_strlen_zero(arglist.variable)) { 00151 ast_log(LOG_WARNING, "Invalid! Usage: Read(variable[|filename][|maxdigits][|option][|attempts][|timeout])\n\n"); 00152 ast_module_user_remove(u); 00153 return -1; 00154 } 00155 ts=NULL; 00156 if (ast_test_flag(&flags,OPT_INDICATION)) { 00157 if (!ast_strlen_zero(arglist.filename)) { 00158 ts = ast_get_indication_tone(chan->zone,arglist.filename); 00159 } 00160 } 00161 if (chan->_state != AST_STATE_UP) { 00162 if (ast_test_flag(&flags,OPT_SKIP)) { 00163 /* At the user's option, skip if the line is not up */ 00164 pbx_builtin_setvar_helper(chan, arglist.variable, "\0"); 00165 ast_module_user_remove(u); 00166 return 0; 00167 } else if (!ast_test_flag(&flags,OPT_NOANSWER)) { 00168 /* Otherwise answer unless we're supposed to read while on-hook */ 00169 res = ast_answer(chan); 00170 } 00171 } 00172 if (!res) { 00173 pbx_builtin_setvar_helper(chan, "READSTATUS", "SUCCESS"); 00174 while (tries && !res) { 00175 ast_stopstream(chan); 00176 if (ts && ts->data[0]) { 00177 if (!to) 00178 to = chan->pbx ? chan->pbx->rtimeout * 1000 : 6000; 00179 res = ast_playtones_start(chan, 0, ts->data, 0); 00180 for (x = 0; x < maxdigits; ) { 00181 res = ast_waitfordigit(chan, to); 00182 ast_playtones_stop(chan); 00183 if (res < 1) { 00184 tmp[x]='\0'; 00185 pbx_builtin_setvar_helper(chan, "READSTATUS", "TIMEOUT"); 00186 break; 00187 } 00188 tmp[x++] = res; 00189 if (tmp[x-1] == '#') { 00190 tmp[x-1] = '\0'; 00191 break; 00192 } 00193 } 00194 } else { 00195 res = ast_app_getdata(chan, arglist.filename, tmp, maxdigits, to); 00196 /* ast_app_getdata -> ast_readstring -> ast_readstringfull returns 1 on timeout */ 00197 if (res == 1) 00198 pbx_builtin_setvar_helper(chan, "READSTATUS", "TIMEOUT"); 00199 } 00200 if (res > -1) { 00201 pbx_builtin_setvar_helper(chan, arglist.variable, tmp); 00202 if (!ast_strlen_zero(tmp)) { 00203 if (option_verbose > 2) 00204 ast_verbose(VERBOSE_PREFIX_3 "User entered '%s'\n", tmp); 00205 tries = 0; 00206 } else { 00207 tries--; 00208 if (option_verbose > 2) { 00209 if (tries) 00210 ast_verbose(VERBOSE_PREFIX_3 "User entered nothing, %d chance%s left\n", tries, (tries != 1) ? "s" : ""); 00211 else 00212 ast_verbose(VERBOSE_PREFIX_3 "User entered nothing.\n"); 00213 } 00214 } 00215 res = 0; 00216 } else { 00217 pbx_builtin_setvar_helper(chan, arglist.variable, tmp); 00218 if (option_verbose > 2) 00219 ast_verbose(VERBOSE_PREFIX_3 "User disconnected\n"); 00220 } 00221 } 00222 } 00223 ast_module_user_remove(u); 00224 return res; 00225 }
static int unload_module | ( | void | ) | [static] |
Definition at line 227 of file app_read.c.
References ast_module_user_hangup_all, and ast_unregister_application().
00228 { 00229 int res; 00230 00231 res = ast_unregister_application(app); 00232 00233 ast_module_user_hangup_all(); 00234 00235 return res; 00236 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "Read Variable Application" , .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 243 of file app_read.c.
char* app = "Read" [static] |
Definition at line 60 of file app_read.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 243 of file app_read.c.
char* descrip [static] |
Definition at line 64 of file app_read.c.
struct ast_app_option read_app_options[128] = { [ 's' ] = { .flag = OPT_SKIP }, [ 'i' ] = { .flag = OPT_INDICATION }, [ 'n' ] = { .flag = OPT_NOANSWER },} [static] |
Definition at line 58 of file app_read.c.
enum { ... } read_option_flags |
char* synopsis = "Read a variable" [static] |
Definition at line 62 of file app_read.c.