#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/pbx.h"
#include "asterisk/channel.h"
#include "asterisk/app.h"
#include "asterisk/module.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 , .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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } |
static char * | app = "Read" |
static 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 79 of file app_read.c.
anonymous enum |
Definition at line 39 of file app_read.c.
00039 { 00040 OPT_SKIP = (1 << 0), 00041 OPT_INDICATION = (1 << 1), 00042 OPT_NOANSWER = (1 << 2), 00043 } read_option_flags;
static void __reg_module | ( | void | ) | [static] |
Definition at line 231 of file app_read.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 231 of file app_read.c.
static int load_module | ( | void | ) | [static] |
Definition at line 226 of file app_read.c.
References ast_register_application, and read_exec().
00227 { 00228 return ast_register_application(app, read_exec, synopsis, descrip); 00229 }
static int read_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 81 of file app_read.c.
References ast_channel::_state, ast_answer(), AST_APP_ARG, ast_app_getdata(), ast_app_parse_options(), ast_check_hangup(), AST_DECLARE_APP_ARGS, ast_get_indication_tone(), AST_GETDATA_COMPLETE, AST_GETDATA_EMPTY_END_TERMINATED, AST_GETDATA_INTERRUPTED, AST_GETDATA_TIMEOUT, ast_log(), ast_playtones_start(), ast_playtones_stop(), AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_stopstream(), ast_strdupa, ast_strlen_zero(), ast_test_flag, ast_verb, ast_waitfordigit(), chan, tone_zone_sound::data, ast_flags::flags, LOG_WARNING, OPT_INDICATION, OPT_NOANSWER, OPT_SKIP, pbx_builtin_setvar_helper(), status, and ast_channel::zone.
Referenced by load_module().
00082 { 00083 int res = 0; 00084 char tmp[256] = ""; 00085 int maxdigits = 255; 00086 int tries = 1, to = 0, x = 0; 00087 double tosec; 00088 char *argcopy = NULL; 00089 struct tone_zone_sound *ts = NULL; 00090 struct ast_flags flags = {0}; 00091 const char *status = "ERROR"; 00092 00093 AST_DECLARE_APP_ARGS(arglist, 00094 AST_APP_ARG(variable); 00095 AST_APP_ARG(filename); 00096 AST_APP_ARG(maxdigits); 00097 AST_APP_ARG(options); 00098 AST_APP_ARG(attempts); 00099 AST_APP_ARG(timeout); 00100 ); 00101 00102 pbx_builtin_setvar_helper(chan, "READSTATUS", status); 00103 if (ast_strlen_zero(data)) { 00104 ast_log(LOG_WARNING, "Read requires an argument (variable)\n"); 00105 return 0; 00106 } 00107 00108 argcopy = ast_strdupa(data); 00109 00110 AST_STANDARD_APP_ARGS(arglist, argcopy); 00111 00112 if (!ast_strlen_zero(arglist.options)) { 00113 ast_app_parse_options(read_app_options, &flags, NULL, arglist.options); 00114 } 00115 00116 if (!ast_strlen_zero(arglist.attempts)) { 00117 tries = atoi(arglist.attempts); 00118 if (tries <= 0) 00119 tries = 1; 00120 } 00121 00122 if (!ast_strlen_zero(arglist.timeout)) { 00123 tosec = atof(arglist.timeout); 00124 if (tosec <= 0) 00125 to = 0; 00126 else 00127 to = tosec * 1000.0; 00128 } 00129 00130 if (ast_strlen_zero(arglist.filename)) { 00131 arglist.filename = NULL; 00132 } 00133 if (!ast_strlen_zero(arglist.maxdigits)) { 00134 maxdigits = atoi(arglist.maxdigits); 00135 if ((maxdigits < 1) || (maxdigits > 255)) { 00136 maxdigits = 255; 00137 } else 00138 ast_verb(3, "Accepting a maximum of %d digits.\n", maxdigits); 00139 } 00140 if (ast_strlen_zero(arglist.variable)) { 00141 ast_log(LOG_WARNING, "Invalid! Usage: Read(variable[,filename][,maxdigits][,option][,attempts][,timeout])\n\n"); 00142 return 0; 00143 } 00144 if (ast_test_flag(&flags, OPT_INDICATION)) { 00145 if (! ast_strlen_zero(arglist.filename)) { 00146 ts = ast_get_indication_tone(chan->zone, arglist.filename); 00147 } 00148 } 00149 if (chan->_state != AST_STATE_UP) { 00150 if (ast_test_flag(&flags, OPT_SKIP)) { 00151 /* At the user's option, skip if the line is not up */ 00152 pbx_builtin_setvar_helper(chan, arglist.variable, ""); 00153 pbx_builtin_setvar_helper(chan, "READSTATUS", "SKIPPED"); 00154 return 0; 00155 } else if (!ast_test_flag(&flags, OPT_NOANSWER)) { 00156 /* Otherwise answer unless we're supposed to read while on-hook */ 00157 res = ast_answer(chan); 00158 } 00159 } 00160 if (!res) { 00161 while (tries && !res) { 00162 ast_stopstream(chan); 00163 if (ts && ts->data[0]) { 00164 if (!to) 00165 to = chan->pbx ? chan->pbx->rtimeoutms : 6000; 00166 res = ast_playtones_start(chan, 0, ts->data, 0); 00167 for (x = 0; x < maxdigits; ) { 00168 res = ast_waitfordigit(chan, to); 00169 ast_playtones_stop(chan); 00170 if (res < 1) { 00171 if (res == 0) 00172 status = "TIMEOUT"; 00173 tmp[x]='\0'; 00174 break; 00175 } 00176 tmp[x++] = res; 00177 if (tmp[x-1] == '#') { 00178 tmp[x-1] = '\0'; 00179 status = "OK"; 00180 break; 00181 } 00182 if (x >= maxdigits) { 00183 status = "OK"; 00184 } 00185 } 00186 } else { 00187 res = ast_app_getdata(chan, arglist.filename, tmp, maxdigits, to); 00188 if (res == AST_GETDATA_COMPLETE || res == AST_GETDATA_EMPTY_END_TERMINATED) 00189 status = "OK"; 00190 else if (res == AST_GETDATA_TIMEOUT) 00191 status = "TIMEOUT"; 00192 else if (res == AST_GETDATA_INTERRUPTED) 00193 status = "INTERRUPTED"; 00194 } 00195 if (res > -1) { 00196 pbx_builtin_setvar_helper(chan, arglist.variable, tmp); 00197 if (!ast_strlen_zero(tmp)) { 00198 ast_verb(3, "User entered '%s'\n", tmp); 00199 tries = 0; 00200 } else { 00201 tries--; 00202 if (tries) 00203 ast_verb(3, "User entered nothing, %d chance%s left\n", tries, (tries != 1) ? "s" : ""); 00204 else 00205 ast_verb(3, "User entered nothing.\n"); 00206 } 00207 res = 0; 00208 } else { 00209 pbx_builtin_setvar_helper(chan, arglist.variable, tmp); 00210 ast_verb(3, "User disconnected\n"); 00211 } 00212 } 00213 } 00214 00215 if (ast_check_hangup(chan)) 00216 status = "HANGUP"; 00217 pbx_builtin_setvar_helper(chan, "READSTATUS", status); 00218 return 0; 00219 }
static int unload_module | ( | void | ) | [static] |
Definition at line 221 of file app_read.c.
References ast_unregister_application().
00222 { 00223 return ast_unregister_application(app); 00224 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .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 = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 231 of file app_read.c.
char* app = "Read" [static] |
Definition at line 51 of file app_read.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 231 of file app_read.c.
char* descrip [static] |
Definition at line 55 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 49 of file app_read.c.
enum { ... } read_option_flags |
char* synopsis = "Read a variable" [static] |
Definition at line 53 of file app_read.c.