Index: app.c =================================================================== --- app.c (revision 49865) +++ app.c (working copy) @@ -149,7 +149,78 @@ return res; } +/*! \param c The channel to read from + * \param prompt The file to stream to the channel + * \param s The string to read in to. Must be at least the size of your length + * \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_better(struct ast_channel *c, char *prompt, char *s, int maxlen, int timeout) +{ + int res = 0; + int to,fto; + int mres = 0; + int add = 0; + + /* XXX Merge with full version? XXX */ + if (maxlen) + s[0] = '\0'; + if (prompt) { + + char *back = prompt; + char *front; + ast_stopstream(c); + while (!res && (front = strsep(&back, "&"))) { + res = ast_streamfile(c, front, c->language); + if (res) { + ast_log(LOG_WARNING, "ast_streamfile failed on %s for %s\n", c->name, front); + res = 0; + mres = 1; + } + res = ast_waitstream(c, AST_DIGIT_ANY); + ast_stopstream(c); + } + if (res < 0) + return res; + } + + fto = c->pbx ? c->pbx->rtimeout * 1000 : 6000; + to = c->pbx ? c->pbx->dtimeout * 1000 : 2000; + + if (timeout > 0) + fto = to = timeout; + if (timeout < 0) + fto = to = 1000000000; + + /* Interrupted by a digit */ + if (res) { + /* only wanted one digit -- return it */ + if (maxlen == 1) { + s[0] = res; + s[1] = '\0'; + return 0; + } else { + /* reduce digits to collect */ + maxlen = maxlen - 1; + add = res; + } + } + + res = ast_readstring(c, s, maxlen, to, fto, "#"); + + /* add on the leading digit captured during the prompt */ + if ((add) && (!res)) { + char tmp[maxlen + 1]; + tmp[0] = add; + sprintf(&tmp[1], "%s", s); + sprintf(s, "%s", tmp); + } + + return res; +} + + int ast_app_getdata_full(struct ast_channel *c, char *prompt, char *s, int maxlen, int timeout, int audiofd, int ctrlfd) { int res, to, fto;