diff options
author | jeremy <jeremy@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-03-21 00:33:05 +0000 |
---|---|---|
committer | jeremy <jeremy@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-03-21 00:33:05 +0000 |
commit | 90d10fafd9741fe4fea60e9eec6b1024e303f2c4 (patch) | |
tree | 4c4abf4a80d01e82bd49711a2a44008fc6434a0f /apps | |
parent | 8113df26dc123e879ecd76a264c4aecf3ba3eb77 (diff) |
Enhance to accept a maximum of N digits. Bug #1261
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@2509 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps')
-rwxr-xr-x | apps/app_read.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/apps/app_read.c b/apps/app_read.c index fcb89fd94..7a5027386 100755 --- a/apps/app_read.c +++ b/apps/app_read.c @@ -31,9 +31,13 @@ static char *app = "Read"; 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 @@ static int read_exec(struct ast_channel *chan, void *data) 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 @@ static int read_exec(struct ast_channel *chan, void *data) 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 @@ static int read_exec(struct ast_channel *chan, void *data) } 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); |