Index: apps/app_read.c
===================================================================
--- apps/app_read.c (revision 381515)
+++ apps/app_read.c (working copy)
@@ -77,6 +77,12 @@
+
@@ -116,12 +122,14 @@
OPT_SKIP = (1 << 0),
OPT_INDICATION = (1 << 1),
OPT_NOANSWER = (1 << 2),
+ OPT_HASH = (1 << 3),
};
AST_APP_OPTIONS(read_app_options, {
AST_APP_OPTION('s', OPT_SKIP),
AST_APP_OPTION('i', OPT_INDICATION),
AST_APP_OPTION('n', OPT_NOANSWER),
+ AST_APP_OPTION('h', OPT_HASH),
});
static char *app = "Read";
@@ -185,6 +193,12 @@
} else
ast_verb(3, "Accepting a maximum of %d digits.\n", maxdigits);
}
+
+ if (ast_test_flag(&flags, OPT_HASH) && to == 0 && maxdigits == 255) {
+ ast_log(LOG_ERROR, "Read(): used option h without timeout and without maxdigits");
+ return 0;
+ }
+
if (ast_strlen_zero(arglist.variable)) {
ast_log(LOG_WARNING, "Invalid! Usage: Read(variable[,filename][,maxdigits][,option][,attempts][,timeout])\n\n");
return 0;
@@ -222,7 +236,7 @@
break;
}
tmp[x++] = res;
- if (tmp[x-1] == '#') {
+ if (tmp[x-1] == '#' && !ast_test_flag(&flags, OPT_HASH)) {
tmp[x-1] = '\0';
status = "OK";
break;
@@ -233,8 +247,33 @@
}
} else {
res = ast_app_getdata(chan, arglist.filename, tmp, maxdigits, to);
- if (res == AST_GETDATA_COMPLETE || res == AST_GETDATA_EMPTY_END_TERMINATED)
+ if (res == AST_GETDATA_COMPLETE || res == AST_GETDATA_EMPTY_END_TERMINATED) {
+ if (!to) {
+ to = ast_channel_pbx(chan) ? ast_channel_pbx(chan)->rtimeoutms : 6000;
+ }
status = "OK";
+ x = strlen(tmp);
+ if (x < maxdigits && ast_test_flag(&flags, OPT_HASH))
+ res = tmp[x++] = '#';
+ while (x < maxdigits && ast_test_flag(&flags, OPT_HASH) && res) {
+ res = ast_waitfordigit(chan, to);
+ if (res < 1) {
+ if (res == 0)
+ status = "TIMEOUT";
+ tmp[x] = '\0';
+ break;
+ }
+ tmp[x++] = res;
+ if (tmp[x-1] == '#' && !ast_test_flag(&flags, OPT_HASH)) {
+ tmp[x-1] = '\0';
+ status = "OK";
+ break;
+ }
+ if (x >= maxdigits) {
+ status = "OK";
+ }
+ }
+ }
else if (res == AST_GETDATA_TIMEOUT)
status = "TIMEOUT";
else if (res == AST_GETDATA_INTERRUPTED)