aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorespiceland <espiceland@f38db490-d61c-443f-a65b-d21fe96a405b>2010-11-19 19:24:05 +0000
committerespiceland <espiceland@f38db490-d61c-443f-a65b-d21fe96a405b>2010-11-19 19:24:05 +0000
commit4fe0a944d54f92d185ef430feb80f326d6f2be5c (patch)
tree0f3f0673f2dc4be6e75867d75e32f49f50ee260a
parent9a426eb9fefb940cf2e3c852151638b775abfa6c (diff)
Add extra functionality to AGI command WAIT FOR DIGIT.
Add the ability to play a sound file, listen for more than just one digit, specify escape characters. Backwards compatible (to work with only timeout specified). (closes issue #15531) Reported by: diLLec Patches: asterisk-res_agi-203638-patched.patch uploaded by diLLec (license 839) Tested by: diLLec, espiceland git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@295552 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--res/res_agi.c77
1 files changed, 74 insertions, 3 deletions
diff --git a/res/res_agi.c b/res/res_agi.c
index 75f2a1bdf..ed9d1b2cc 100644
--- a/res/res_agi.c
+++ b/res/res_agi.c
@@ -446,12 +446,83 @@ static int handle_waitfordigit(struct ast_channel *chan, AGI *agi, int argc, cha
{
int res;
int to;
- if (argc != 4)
+ char *valid_dtmf_digits = AST_DIGIT_ANY;
+ char *previously_die_on = "#";
+ char *digits = NULL;
+ char *escape_digits = NULL;
+ char *voicefile = NULL;
+ int maxdigits = 1;
+
+ if (argc < 4)
return RESULT_SHOWUSAGE;
if (sscanf(argv[3], "%30d", &to) != 1)
return RESULT_SHOWUSAGE;
- res = ast_waitfordigit_full(chan, to, agi->audio, agi->ctrl);
- fdprintf(agi->fd, "200 result=%d\n", res);
+
+ /* Answer the chan */
+ if (chan->_state != AST_STATE_UP)
+ res = ast_answer(chan);
+
+ /* soundfile specified */
+ if (argc >= 5) {
+
+ /* escape characters defined */
+ if (argc >= 6)
+ valid_dtmf_digits = (char *) argv[5];
+
+ /* maxdigits */
+ if (argc >= 7 && (sscanf(argv[6], "%d", &maxdigits) != 1))
+ return RESULT_SHOWUSAGE;
+
+ /* escape before escape chars on */
+ if (argc >= 8)
+ previously_die_on = (char *) argv[7];
+
+ voicefile = (char *) argv[4];
+ res = ast_streamfile(chan, voicefile, chan->language);
+ if (res < 0)
+ return RESULT_FAILURE;
+
+ /* allocate space for the digits (2 chars per digit + \0 - <digit>|<digit>|...) */
+ digits = (char *)ast_malloc(maxdigits * 2 + 1);
+ ast_copy_string(digits, "", 1);
+
+ /* catenate the escape digits together with previously die digits */
+ escape_digits = (char *)ast_malloc(strlen(valid_dtmf_digits) + strlen(previously_die_on)+ 1);
+ ast_copy_string(escape_digits, valid_dtmf_digits, sizeof(valid_dtmf_digits));
+ strcat(escape_digits, previously_die_on);
+
+ if (chan->stream) {
+ int dtmf_count = 0;
+ do {
+ char buf[3];
+ res = ast_waitstream_full(chan, escape_digits, agi->audio, agi->ctrl);
+ if (res > 0) {
+ if (strchr(previously_die_on, res) != NULL) {
+ /* previously die character found - end loop */
+ ast_log(LOG_DEBUG, "prev die digit %c pressed\n", res);
+ break;
+ } else {
+ /* chars in valid_dtmf_digits found */
+ ast_log(LOG_DEBUG, "dtmf turn=%d of %d | res=%d\n", dtmf_count, maxdigits, res);
+ sprintf(buf, "%c", res);
+ strcat(digits, buf);
+ dtmf_count++;
+ }
+ }
+ } while ( strchr(previously_die_on, res) == NULL && dtmf_count < maxdigits && chan->stream);
+ ast_stopstream(chan);
+ fdprintf(agi->fd, "200 result=%s\n", digits);
+ } else {
+ res = ast_waitfordigit_full(chan, to, agi->audio, agi->ctrl);
+ fdprintf(agi->fd, "200 result=%c\n", res);
+ }
+ } else {
+ res = ast_waitfordigit_full(chan, to, agi->audio, agi->ctrl);
+ fdprintf(agi->fd, "200 result=%c\n", res);
+ }
+
+ ast_free(escape_digits);
+ ast_free(digits);
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
}