summaryrefslogtreecommitdiff
path: root/main/pbx_builtins.c
diff options
context:
space:
mode:
authorCorey Farrell <git@cfware.com>2017-07-12 14:24:36 -0400
committerCorey Farrell <git@cfware.com>2017-07-12 19:08:23 -0400
commit6b138046e7db59e975fc06ee3aea54fe0c143f5d (patch)
tree5d1297d795a8640b0b1f15b52652131688541197 /main/pbx_builtins.c
parent27aeca3594ae6618ffcafc8fe764fb0c9507ec14 (diff)
core: Add digit filtering to ast_waitfordigit_full
This adds a parameter to ast_waitfordigit_full which can be used to only stop waiting when certain expected digits are received. Any unexpected DTMF digits are simply ignored. This also creates a new dialplan application WaitDigit. ASTERISK-27129 #close Change-Id: Id233935ea3d13e71c75a0861834c5936c3700ef9
Diffstat (limited to 'main/pbx_builtins.c')
-rw-r--r--main/pbx_builtins.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/main/pbx_builtins.c b/main/pbx_builtins.c
index bc27b0d58..9d43c10ff 100644
--- a/main/pbx_builtins.c
+++ b/main/pbx_builtins.c
@@ -580,6 +580,42 @@
<para>This application waits for a specified number of <replaceable>seconds</replaceable>.</para>
</description>
</application>
+ <application name="WaitDigit" language="en_US">
+ <synopsis>
+ Waits for a digit to be entered.
+ </synopsis>
+ <syntax>
+ <parameter name="seconds">
+ <para>Can be passed with fractions of a second. For example, <literal>1.5</literal> will ask the
+ application to wait for 1.5 seconds.</para>
+ </parameter>
+ <parameter name="digits">
+ <para>Digits to accept, all others are ignored.</para>
+ </parameter>
+ </syntax>
+ <description>
+ <para>This application waits for the user to press one of the accepted
+ <replaceable>digits</replaceable> for a specified number of
+ <replaceable>seconds</replaceable>.</para>
+ <variablelist>
+ <variable name="WAITDIGITSTATUS">
+ <para>This is the final status of the command</para>
+ <value name="ERROR">Parameters are invalid.</value>
+ <value name="DTMF">An accepted digit was received.</value>
+ <value name="TIMEOUT">The timeout passed before any acceptable digits were received.</value>
+ <value name="CANCEL">The channel has hungup or was redirected.</value>
+ </variable>
+ <variable name="WAITDIGITRESULT">
+ <para>The digit that was received, only set if
+ <variable>WAITDIGITSTATUS</variable> is <literal>DTMF</literal>.</para>
+ </variable>
+ </variablelist>
+ </description>
+ <see-also>
+ <ref type="application">Wait</ref>
+ <ref type="application">WaitExten</ref>
+ </see-also>
+ </application>
<application name="WaitExten" language="en_US">
<synopsis>
Waits for an extension to be entered.
@@ -957,6 +993,47 @@ static int pbx_builtin_wait(struct ast_channel *chan, const char *data)
/*!
* \ingroup applications
*/
+static int pbx_builtin_waitdigit(struct ast_channel *chan, const char *data)
+{
+ int res;
+ int ms;
+ char *parse;
+ AST_DECLARE_APP_ARGS(args,
+ AST_APP_ARG(timeout);
+ AST_APP_ARG(digits);
+ );
+
+ parse = ast_strdupa(data);
+ AST_STANDARD_APP_ARGS(args, parse);
+
+ if (ast_app_parse_timelen(args.timeout, &ms, TIMELEN_SECONDS) || ms < 0) {
+ pbx_builtin_setvar_helper(chan, "WAITDIGITSTATUS", "ERROR");
+ return 0;
+ }
+
+ /* Wait for "n" seconds */
+ res = ast_waitfordigit_full(chan, ms, S_OR(args.digits, AST_DIGIT_ANY), -1, -1);
+ if (res < 0) {
+ pbx_builtin_setvar_helper(chan, "WAITDIGITSTATUS", "CANCEL");
+ return -1;
+ }
+
+ if (res == 0) {
+ pbx_builtin_setvar_helper(chan, "WAITDIGITSTATUS", "TIMEOUT");
+ } else {
+ char key[2];
+
+ snprintf(key, sizeof(key), "%c", res);
+ pbx_builtin_setvar_helper(chan, "WAITDIGITRESULT", key);
+ pbx_builtin_setvar_helper(chan, "WAITDIGITSTATUS", "DTMF");
+ }
+
+ return 0;
+}
+
+/*!
+ * \ingroup applications
+ */
static int pbx_builtin_waitexten(struct ast_channel *chan, const char *data)
{
int ms, res;
@@ -1410,6 +1487,7 @@ struct pbx_builtin {
{ "SayPhonetic", pbx_builtin_sayphonetic },
{ "SetAMAFlags", pbx_builtin_setamaflags },
{ "Wait", pbx_builtin_wait },
+ { "WaitDigit", pbx_builtin_waitdigit },
{ "WaitExten", pbx_builtin_waitexten }
};