diff options
-rw-r--r-- | apps/app_read.c | 6 | ||||
-rw-r--r-- | include/asterisk/app.h | 10 | ||||
-rw-r--r-- | main/app.c | 10 | ||||
-rw-r--r-- | main/channel.c | 21 |
4 files changed, 33 insertions, 14 deletions
diff --git a/apps/app_read.c b/apps/app_read.c index a5aa7710b..2e69d2239 100644 --- a/apps/app_read.c +++ b/apps/app_read.c @@ -185,11 +185,11 @@ static int read_exec(struct ast_channel *chan, void *data) } } else { res = ast_app_getdata(chan, arglist.filename, tmp, maxdigits, to); - if (res == 0) + if (res == AST_GETDATA_COMPLETE || res == AST_GETDATA_EMPTY_END_TERMINATED) status = "OK"; - else if (res == 1) + else if (res == AST_GETDATA_TIMEOUT) status = "TIMEOUT"; - else if (res == 2) + else if (res == AST_GETDATA_INTERRUPTED) status = "INTERRUPTED"; } if (res > -1) { diff --git a/include/asterisk/app.h b/include/asterisk/app.h index bc61aa561..4951169ec 100644 --- a/include/asterisk/app.h +++ b/include/asterisk/app.h @@ -204,6 +204,16 @@ int ast_play_and_record(struct ast_channel *chan, const char *playfile, const ch 'silencethreshold' or use '-1' for either or both parameters for defaults. */ int ast_play_and_prepend(struct ast_channel *chan, char *playfile, char *recordfile, int maxtime_sec, char *fmt, int *duration, int beep, int silencethreshold, int maxsilence_ms); +enum ast_getdata_result { + AST_GETDATA_FAILED = -1, + AST_GETDATA_COMPLETE = 0, + AST_GETDATA_TIMEOUT = 1, + AST_GETDATA_INTERRUPTED = 2, + /*! indicates a user terminated empty string rather than an empty string resulting + * from a timeout or other factors */ + AST_GETDATA_EMPTY_END_TERMINATED = 3, +}; + enum AST_LOCK_RESULT { AST_LOCK_SUCCESS = 0, AST_LOCK_TIMEOUT = -1, diff --git a/main/app.c b/main/app.c index a81038804..8528ab53a 100644 --- a/main/app.c +++ b/main/app.c @@ -111,7 +111,7 @@ int ast_app_dtget(struct ast_channel *chan, const char *context, char *collect, * \param maxlen How many digits to read (maximum) * \param timeout set timeout to 0 for "standard" timeouts. Set timeout to -1 for * "ludicrous time" (essentially never times out) */ -int ast_app_getdata(struct ast_channel *c, const char *prompt, char *s, int maxlen, int timeout) +enum ast_getdata_result ast_app_getdata(struct ast_channel *c, const char *prompt, char *s, int maxlen, int timeout) { int res = 0, to, fto; char *front, *filename; @@ -148,10 +148,14 @@ int ast_app_getdata(struct ast_channel *c, const char *prompt, char *s, int maxl to = c->pbx ? c->pbx->dtimeoutms : 2000; } res = ast_readstring(c, s, maxlen, to, fto, "#"); - if (!ast_strlen_zero(s)) + if (res == AST_GETDATA_EMPTY_END_TERMINATED) { return res; + } + if (!ast_strlen_zero(s)) { + return res; + } } - + return res; } diff --git a/main/channel.c b/main/channel.c index 81472716f..e2e434aaf 100644 --- a/main/channel.c +++ b/main/channel.c @@ -3683,20 +3683,25 @@ int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, in d = ast_waitfordigit_full(c, to, audiofd, ctrlfd); } if (d < 0) - return -1; + return AST_GETDATA_FAILED; if (d == 0) { - s[pos]='\0'; - return 1; + s[pos] = '\0'; + return AST_GETDATA_TIMEOUT; } if (d == 1) { - s[pos]='\0'; - return 2; + s[pos] = '\0'; + return AST_GETDATA_INTERRUPTED; + } + if (strchr(enders, d) && (pos == 0)) { + s[pos] = '\0'; + return AST_GETDATA_EMPTY_END_TERMINATED; } - if (!strchr(enders, d)) + if (!strchr(enders, d)) { s[pos++] = d; + } if (strchr(enders, d) || (pos >= len)) { - s[pos]='\0'; - return 0; + s[pos] = '\0'; + return AST_GETDATA_COMPLETE; } to = timeout; } |