]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
app_read: Add an option to return terminator on empty digits.
authorMike Bradeen <mbradeen@sangoma.com>
Mon, 30 Jan 2023 23:14:30 +0000 (16:14 -0700)
committerGeorge Joseph <gjoseph@digium.com>
Mon, 27 Feb 2023 19:42:58 +0000 (13:42 -0600)
Adds 'e' option to allow Read() to return the terminator as the
dialed digits in the case where only the terminator is entered.

ie; if "#" is entered, return "#" if the 'e' option is set and ""
if it is not.

ASTERISK-30411

Change-Id: I49f3221824330a193a20c660f99da0f1fc2cbbc5

apps/app_read.c
doc/CHANGES-staging/app_read_return_terminator.txt [new file with mode: 0644]

index f4a965c8b46d36b64772a2803f4e677467b20d44..e2ac60cc96a1ef33511309b688df275a609ae980 100644 (file)
                                                and you will need to rely on duration and max digits
                                                for ending input.</para>
                                        </option>
+                                       <option name="e">
+                                               <para>to read the terminator as the digit string if the
+                                               only digit read is the terminator. This is for cases
+                                               where the terminator is a valid digit, but only by itself.
+                                               ie; <literal>1234</literal> and <literal>#</literal> are
+                                               valid, but <literal>1234#</literal> is not.</para>
+                                       </option>
                                </optionlist>
                        </parameter>
                        <parameter name="attempts">
@@ -125,6 +132,7 @@ enum read_option_flags {
        OPT_INDICATION = (1 << 1),
        OPT_NOANSWER = (1 << 2),
        OPT_TERMINATOR = (1 << 3),
+       OPT_KEEP_TERMINATOR = (1 << 4),
 };
 
 enum {
@@ -138,6 +146,7 @@ AST_APP_OPTIONS(read_app_options, {
        AST_APP_OPTION('i', OPT_INDICATION),
        AST_APP_OPTION('n', OPT_NOANSWER),
        AST_APP_OPTION_ARG('t', OPT_TERMINATOR, OPT_ARG_TERMINATOR),
+       AST_APP_OPTION('e', OPT_KEEP_TERMINATOR),
 });
 
 static char *app = "Read";
@@ -261,12 +270,20 @@ static int read_exec(struct ast_channel *chan, const char *data)
                                }
                        } else {
                                res = ast_app_getdata_terminator(chan, arglist.filename, tmp, maxdigits, to, terminator);
-                               if (res == AST_GETDATA_COMPLETE || res == AST_GETDATA_EMPTY_END_TERMINATED)
+                               if (res == AST_GETDATA_COMPLETE) {
+                                       status = "OK";
+                               } else if (res == AST_GETDATA_EMPTY_END_TERMINATED) {
+                                       if (ast_test_flag(&flags, OPT_KEEP_TERMINATOR)) {
+                                               /* if the option is set to do so, read the
+                                                  returned string as the terminator string */
+                                               ast_copy_string(tmp, terminator, sizeof(tmp));
+                                       }
                                        status = "OK";
-                               else if (res == AST_GETDATA_TIMEOUT)
+                               } else if (res == AST_GETDATA_TIMEOUT) {
                                        status = "TIMEOUT";
-                               else if (res == AST_GETDATA_INTERRUPTED)
+                               } else if (res == AST_GETDATA_INTERRUPTED) {
                                        status = "INTERRUPTED";
+                               }
                        }
                        if (res > -1) {
                                pbx_builtin_setvar_helper(chan, arglist.variable, tmp);
diff --git a/doc/CHANGES-staging/app_read_return_terminator.txt b/doc/CHANGES-staging/app_read_return_terminator.txt
new file mode 100644 (file)
index 0000000..2987f77
--- /dev/null
@@ -0,0 +1,5 @@
+Subject: app_read
+
+A new option 'e' has been added to allow Read() to return the
+terminator as the dialed digits in the case where only the terminator
+is entered.