[Asterisk-code-review] say.c: Honor requests for DTMF interruption. (asterisk[16])

Sean Bright asteriskteam at digium.com
Thu Dec 23 16:49:08 CST 2021


Sean Bright has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/17712 )


Change subject: say.c: Honor requests for DTMF interruption.
......................................................................

say.c: Honor requests for DTMF interruption.

SayAlpha, SayAlphaCase, SayDigits, SayMoney, SayNumber, SayOrdinal,
and SayPhonetic all claim to allow DTMF interruption if the
SAY_DTMF_INTERRUPT channel variable is set to a truthy value, but we
are failing to break out of a given 'say' application if DTMF actually
occurs.

ASTERISK-29816 #close

Change-Id: I6a96e0130560831d2cb45164919862b9bcb6287e
---
M main/pbx_builtins.c
M main/say.c
2 files changed, 34 insertions(+), 67 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/12/17712/1

diff --git a/main/pbx_builtins.c b/main/pbx_builtins.c
index eae4c6b..93b0af0 100644
--- a/main/pbx_builtins.c
+++ b/main/pbx_builtins.c
@@ -1323,6 +1323,25 @@
 	return pbx_builtin_goto(chan, branch);
 }
 
+/*!
+ * \brief Determine if DTMF interruption was requested.
+ *
+ * If the SAY_DTMF_INTERRUPT channel variable is truthy, the caller has
+ * requested DTMF interruption be enabled.
+ *
+ * \param chan the channel to examine.
+ */
+static int permit_dtmf_interrupt(struct ast_channel *chan)
+{
+	int interrupt;
+
+	ast_channel_lock(chan);
+	interrupt = ast_true(pbx_builtin_getvar_helper(chan, "SAY_DTMF_INTERRUPT"));
+	ast_channel_unlock(chan);
+
+	return interrupt;
+}
+
 static int pbx_builtin_saynumber(struct ast_channel *chan, const char *data)
 {
 	char tmp[256];
@@ -1330,15 +1349,7 @@
 	int number_val;
 	char *options;
 	int res;
-	int interrupt = 0;
-	const char *interrupt_string;
-
-	ast_channel_lock(chan);
-	interrupt_string = pbx_builtin_getvar_helper(chan, "SAY_DTMF_INTERRUPT");
-	if (ast_true(interrupt_string)) {
-		interrupt = 1;
-	}
-	ast_channel_unlock(chan);
+	int interrupt = permit_dtmf_interrupt(chan);
 
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "SayNumber requires an argument (number)\n");
@@ -1377,15 +1388,7 @@
 	int number_val;
 	char *options;
 	int res;
-	int interrupt = 0;
-	const char *interrupt_string;
-
-	ast_channel_lock(chan);
-	interrupt_string = pbx_builtin_getvar_helper(chan, "SAY_DTMF_INTERRUPT");
-	if (ast_true(interrupt_string)) {
-		interrupt = 1;
-	}
-	ast_channel_unlock(chan);
+	int interrupt = permit_dtmf_interrupt(chan);
 
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "SayOrdinal requires an argument (number)\n");
@@ -1420,18 +1423,9 @@
 static int pbx_builtin_saydigits(struct ast_channel *chan, const char *data)
 {
 	int res = 0;
-	int interrupt = 0;
-	const char *interrupt_string;
-
-	ast_channel_lock(chan);
-	interrupt_string = pbx_builtin_getvar_helper(chan, "SAY_DTMF_INTERRUPT");
-	if (ast_true(interrupt_string)) {
-		interrupt = 1;
-	}
-	ast_channel_unlock(chan);
 
 	if (data) {
-		res = ast_say_digit_str(chan, data, interrupt ? AST_DIGIT_ANY : "", ast_channel_language(chan));
+		res = ast_say_digit_str(chan, data, permit_dtmf_interrupt(chan) ? AST_DIGIT_ANY : "", ast_channel_language(chan));
 	}
 
 	return res;
@@ -1440,18 +1434,9 @@
 static int pbx_builtin_saymoney(struct ast_channel *chan, const char *data)
 {
 	int res = 0;
-	int interrupt = 0;
-	const char *interrupt_string;
-
-	ast_channel_lock(chan);
-	interrupt_string = pbx_builtin_getvar_helper(chan, "SAY_DTMF_INTERRUPT");
-	if (ast_true(interrupt_string)) {
-		interrupt = 1;
-	}
-	ast_channel_unlock(chan);
 
 	if (data) {
-		res = ast_say_money_str(chan, data, interrupt ? AST_DIGIT_ANY : "", ast_channel_language(chan));
+		res = ast_say_money_str(chan, data, permit_dtmf_interrupt(chan) ? AST_DIGIT_ANY : "", ast_channel_language(chan));
 	}
 
 	return res;
@@ -1462,21 +1447,12 @@
 	int res = 0;
 	int sensitivity = 0;
 	char *parse;
-	int interrupt = 0;
-	const char *interrupt_string;
 
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(options);
 		AST_APP_ARG(characters);
 	);
 
-	ast_channel_lock(chan);
-	interrupt_string = pbx_builtin_getvar_helper(chan, "SAY_DTMF_INTERRUPT");
-	if (ast_true(interrupt_string)) {
-		interrupt = 1;
-	}
-	ast_channel_unlock(chan);
-
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "SayAlphaCase requires two arguments (options, characters)\n");
 		return 0;
@@ -1508,7 +1484,7 @@
 		return 0;
 	}
 
-	res = ast_say_character_str(chan, args.characters, interrupt ? AST_DIGIT_ANY : "", ast_channel_language(chan), sensitivity);
+	res = ast_say_character_str(chan, args.characters, permit_dtmf_interrupt(chan) ? AST_DIGIT_ANY : "", ast_channel_language(chan), sensitivity);
 
 	return res;
 }
@@ -1516,18 +1492,9 @@
 static int pbx_builtin_saycharacters(struct ast_channel *chan, const char *data)
 {
 	int res = 0;
-	int interrupt = 0;
-	const char *interrupt_string;
-
-	ast_channel_lock(chan);
-	interrupt_string = pbx_builtin_getvar_helper(chan, "SAY_DTMF_INTERRUPT");
-	if (ast_true(interrupt_string)) {
-		interrupt = 1;
-	}
-	ast_channel_unlock(chan);
 
 	if (data) {
-		res = ast_say_character_str(chan, data, interrupt ? AST_DIGIT_ANY : "", ast_channel_language(chan), AST_SAY_CASE_NONE);
+		res = ast_say_character_str(chan, data, permit_dtmf_interrupt(chan) ? AST_DIGIT_ANY : "", ast_channel_language(chan), AST_SAY_CASE_NONE);
 	}
 
 	return res;
@@ -1536,18 +1503,11 @@
 static int pbx_builtin_sayphonetic(struct ast_channel *chan, const char *data)
 {
 	int res = 0;
-	int interrupt = 0;
-	const char *interrupt_string;
 
-	ast_channel_lock(chan);
-	interrupt_string = pbx_builtin_getvar_helper(chan, "SAY_DTMF_INTERRUPT");
-	if (ast_true(interrupt_string)) {
-		interrupt = 1;
+	if (data) {
+		res = ast_say_phonetic_str(chan, data, permit_dtmf_interrupt(chan) ? AST_DIGIT_ANY : "", ast_channel_language(chan));
 	}
-	ast_channel_unlock(chan);
 
-	if (data)
-		res = ast_say_phonetic_str(chan, data, interrupt ? AST_DIGIT_ANY : "", ast_channel_language(chan));
 	return res;
 }
 
diff --git a/main/say.c b/main/say.c
index bb0c0a6..54aefe0 100644
--- a/main/say.c
+++ b/main/say.c
@@ -189,6 +189,13 @@
 				res = ast_waitstream_full(chan, ints, audiofd, ctrlfd);
 			else
 				res = ast_waitstream(chan, ints);
+
+			if (res > 0) {
+				/* We were interrupted by a digit */
+				ast_stopstream(chan);
+				ast_free(filenames);
+				return res;
+			}
 		}
 		ast_stopstream(chan);
 	}

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

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: I6a96e0130560831d2cb45164919862b9bcb6287e
Gerrit-Change-Number: 17712
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean at seanbright.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20211223/a7013a09/attachment-0001.html>


More information about the asterisk-code-review mailing list