136 enum read_option_flags {
138 OPT_INDICATION = (1 << 1),
139 OPT_NOANSWER = (1 << 2),
140 OPT_TERMINATOR = (1 << 3),
141 OPT_KEEP_TERMINATOR = (1 << 4),
158 static char *app =
"Read";
160 static int read_exec(
struct ast_channel *chan,
const char *data)
165 int tries = 1, to = 0, x = 0;
167 char *argcopy = NULL;
168 char *opt_args[OPT_ARG_ARRAY_SIZE];
171 const char *status =
"ERROR";
172 char *terminator =
"#";
184 if (ast_strlen_zero(data)) {
185 ast_log(LOG_WARNING,
"Read requires an argument (variable)\n");
193 if (!ast_strlen_zero(arglist.options)) {
197 if (!ast_strlen_zero(arglist.attempts)) {
198 tries = atoi(arglist.attempts);
203 if (!ast_strlen_zero(arglist.timeout)) {
204 tosec = atof(arglist.timeout);
211 if (ast_strlen_zero(arglist.filename)) {
212 arglist.filename = NULL;
214 if (!ast_strlen_zero(arglist.maxdigits)) {
215 maxdigits = atoi(arglist.maxdigits);
216 if ((maxdigits < 1) || (maxdigits > 255)) {
219 ast_verb(3,
"Accepting a maximum of %d digits.\n", maxdigits);
221 if (ast_strlen_zero(arglist.variable)) {
222 ast_log(LOG_WARNING,
"Invalid! Usage: Read(variable[,filename][,maxdigits][,option][,attempts][,timeout])\n\n");
225 if (ast_test_flag(&flags, OPT_INDICATION)) {
226 if (!ast_strlen_zero(arglist.filename)) {
230 if (ast_test_flag(&flags, OPT_TERMINATOR)) {
231 if (!ast_strlen_zero(opt_args[OPT_ARG_TERMINATOR])) {
232 terminator = opt_args[OPT_ARG_TERMINATOR];
238 if (ast_test_flag(&flags, OPT_SKIP)) {
246 }
else if (!ast_test_flag(&flags, OPT_NOANSWER)) {
252 while (tries && !res) {
254 if (ts && ts->
data[0]) {
256 to = ast_channel_pbx(chan) ? ast_channel_pbx(chan)->
rtimeoutms : 6000;
258 for (x = 0; x < maxdigits; ) {
268 if (terminator && strchr(terminator, tmp[x-1])) {
273 if (x >= maxdigits) {
279 if (res == AST_GETDATA_COMPLETE) {
282 if (ast_test_flag(&flags, OPT_KEEP_TERMINATOR)) {
288 }
else if (res == AST_GETDATA_TIMEOUT) {
290 }
else if (res == AST_GETDATA_INTERRUPTED) {
291 status =
"INTERRUPTED";
296 if (!ast_strlen_zero(tmp)) {
297 ast_verb(3,
"User entered '%s'\n", tmp);
302 ast_verb(3,
"User entered nothing, %d chance%s left\n", tries, (tries != 1) ?
"s" :
"");
304 ast_verb(3,
"User entered nothing.\n");
309 ast_verb(3,
"User disconnected\n");
324 static int unload_module(
void)
329 static int load_module(
void)
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
ast_channel_state
ast_channel states
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
void ast_playtones_stop(struct ast_channel *chan)
Stop playing tones on a channel.
int ast_unregister_application(const char *app)
Unregister an application.
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
General Asterisk PBX channel definitions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
static struct ast_tone_zone_sound * ast_tone_zone_sound_unref(struct ast_tone_zone_sound *ts)
Release a reference to an ast_tone_zone_sound.
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Core PBX routines and definitions.
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
enum ast_getdata_result ast_app_getdata_terminator(struct ast_channel *c, const char *prompt, char *s, int maxlen, int timeout, char *terminator)
Plays a stream and gets DTMF data from a channel.
#define AST_APP_OPTION_ARG(option, flagno, argno)
Declares an application option that accepts an argument.
struct ast_tone_zone_sound * ast_get_indication_tone(const struct ast_tone_zone *zone, const char *indication)
Locate a tone zone sound.
Structure used to handle boolean flags.
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...
int ast_waitfordigit(struct ast_channel *c, int ms)
Waits for a digit.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
int ast_answer(struct ast_channel *chan)
Answer a channel.
int ast_playtones_start(struct ast_channel *chan, int vol, const char *tonelist, int interruptible)
Start playing a list of tones on a channel.
const char * data
Description of a tone.
#define AST_APP_OPTION(option, flagno)
Declares an application option that does not accept an argument.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
int ast_stopstream(struct ast_channel *c)
Stops a stream.
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
#define AST_APP_ARG(name)
Define an application argument.