[Asterisk-code-review] app_read: add option to return terminator on empty digits (asterisk[18])

Michael Bradeen asteriskteam at digium.com
Mon Jan 30 17:15:54 CST 2023


Michael Bradeen has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/19883 )


Change subject: app_read: add option to return terminator on empty digits
......................................................................

app_read: add option to return terminator on empty digits

Adds 'e' option to allow app_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
---
M apps/app_read.c
1 file changed, 37 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/83/19883/1

diff --git a/apps/app_read.c b/apps/app_read.c
index f4a965c..1637456 100644
--- a/apps/app_read.c
+++ b/apps/app_read.c
@@ -85,6 +85,10 @@
 						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.</para>
+					</option>
 				</optionlist>
 			</parameter>
 			<parameter name="attempts">
@@ -125,6 +129,7 @@
 	OPT_INDICATION = (1 << 1),
 	OPT_NOANSWER = (1 << 2),
 	OPT_TERMINATOR = (1 << 3),
+	OPT_NOEMPTY = (1 << 4),
 };
 
 enum {
@@ -138,6 +143,7 @@
 	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_NOEMPTY),
 });
 
 static char *app = "Read";
@@ -261,12 +267,23 @@
 				}
 			} 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_TIMEOUT)
+				}
+				else if (res == AST_GETDATA_EMPTY_END_TERMINATED) {
+					if (ast_test_flag(&flags, OPT_NOEMPTY)) {
+						/* 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) {
 					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);

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/19883
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: I49f3221824330a193a20c660f99da0f1fc2cbbc5
Gerrit-Change-Number: 19883
Gerrit-PatchSet: 1
Gerrit-Owner: Michael Bradeen <mbradeen at sangoma.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20230130/874d2678/attachment-0001.html>


More information about the asterisk-code-review mailing list