[Asterisk-cvs] asterisk/apps app_read.c,1.2,1.3
jeremy at lists.digium.com
jeremy at lists.digium.com
Sat Mar 20 19:37:23 CST 2004
Update of /usr/cvsroot/asterisk/apps
In directory mongoose.digium.com:/tmp/cvs-serv15330
Modified Files:
app_read.c
Log Message:
Enhance to accept a maximum of N digits. Bug #1261
Index: app_read.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_read.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- app_read.c 10 Nov 2003 04:54:02 -0000 1.2
+++ app_read.c 21 Mar 2004 00:33:05 -0000 1.3
@@ -31,9 +31,13 @@
static char *synopsis = "Read a variable";
static char *descrip =
-" Read(variable[|filename]): Reads a '#' terminated string of digits from\n"
+" Read(variable[|filename][|maxdigits]): Reads a #-terminated string of digits from\n"
"the user, optionally playing a given filename first. Returns -1 on hangup or\n"
-"error and 0 otherwise.\n";
+"error and 0 otherwise.\n"
+" maxdigits -- maximum acceptable number of digits. Stops reading after maxdigits\n"
+" have been entered (without requiring the user press the '#' key).\n"
+" Defaults to 0 - no limit - wait for the user press the '#' key.\n"
+" Any value below 0 means the same. Max accepted value is 255.\n";
STANDARD_LOCAL_USER;
@@ -44,9 +48,11 @@
int res = 0;
struct localuser *u;
char tmp[256];
- char tmp2[128]="";
+ char tmp2[256]="";
char *filename;
char *stringp;
+ char *maxdigitstr;
+ int maxdigits=255;
if (!data || !strlen((char *)data)) {
ast_log(LOG_WARNING, "Read requires an argument (variable)\n");
return -1;
@@ -55,6 +61,16 @@
stringp=tmp;
strsep(&stringp, "|");
filename = strsep(&stringp, "|");
+ maxdigitstr = strsep(&stringp,"|");
+ if (maxdigitstr)
+ {
+ maxdigits = atoi(maxdigitstr);
+ if ((maxdigits<1) || (maxdigits>255)) {
+ maxdigits = 255;
+ }
+ else
+ ast_verbose(VERBOSE_PREFIX_3 "Accepting a maximum of %i digits.\n", maxdigits);
+ }
if (!strlen(tmp)) {
ast_log(LOG_WARNING, "Read requires an variable name\n");
return -1;
@@ -66,7 +82,7 @@
}
if (!res) {
ast_stopstream(chan);
- res = ast_app_getdata(chan, filename, tmp2, sizeof(tmp2) - 1, 0);
+ res = ast_app_getdata(chan, filename, tmp2, maxdigits, 0);
if (!res)
pbx_builtin_setvar_helper(chan, tmp, tmp2);
ast_verbose(VERBOSE_PREFIX_3 "User entered '%s'\n", tmp2);
More information about the svn-commits
mailing list