[Asterisk-code-review] res_musiconhold: Add option to not play music on hold on unanswered c... (asterisk[20])

sungtae kim asteriskteam at digium.com
Mon Sep 12 09:34:30 CDT 2022


sungtae kim has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/19224 )


Change subject: res_musiconhold: Add option to not play music on hold on unanswered channels
......................................................................

res_musiconhold: Add option to not play music on hold on unanswered channels

This change adds an option, answeredonly, that will prevent music on
hold on channels that are not answered.

ASTERISK-30135

Change-Id: I1ab0defa43a29a26ae39f94c623596cf90fddc08
---
M configs/samples/musiconhold.conf.sample
A doc/CHANGES-staging/res_musiconhold_answeredonly.txt
M res/res_musiconhold.c
3 files changed, 30 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/24/19224/1

diff --git a/configs/samples/musiconhold.conf.sample b/configs/samples/musiconhold.conf.sample
index 2f60108..1737c7a 100644
--- a/configs/samples/musiconhold.conf.sample
+++ b/configs/samples/musiconhold.conf.sample
@@ -82,6 +82,9 @@
 ;               ; in alphabetical order. If 'randstart', the files are sorted
 ;               ; in alphabetical order as well, but the first file is chosen
 ;               ; at random. If unspecified, the sort order is undefined.
+;answeredonly=yes       ; Only allow answered channels to have music on hold.
+                        ; Enabling this will prevent MOH on unanswered channels.
+                        ; (default: "no")
 
 ;[native-alphabetical]
 ;mode=files
diff --git a/doc/CHANGES-staging/res_musiconhold_answeredonly.txt b/doc/CHANGES-staging/res_musiconhold_answeredonly.txt
new file mode 100644
index 0000000..c335184
--- /dev/null
+++ b/doc/CHANGES-staging/res_musiconhold_answeredonly.txt
@@ -0,0 +1,4 @@
+Subject: res_musiconhold_answeredonly
+
+This change adds an option, answeredonly, that will prevent music
+on hold on channels that are not answered.
diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index 9844de0..6196211 100644
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -193,6 +193,8 @@
 	unsigned int delete:1;
 	AST_LIST_HEAD_NOLOCK(, mohdata) members;
 	AST_LIST_ENTRY(mohclass) list;
+	/*!< Play the moh if the channel answered */
+	int answeredonly;
 };
 
 struct mohdata {
@@ -1193,6 +1195,8 @@
 				ast_log(LOG_WARNING, "kill_method '%s' is invalid.  Setting to 'process_group'\n", var->value);
 				mohclass->kill_method = KILL_METHOD_PROCESS_GROUP;
 			}
+		} else if (!strcasecmp(var->name, "answeredonly")) {
+			mohclass->answeredonly = ast_true(var->value) ? 1: 0;
 		}
 	}
 
@@ -1835,6 +1839,11 @@
 		return -1;
 	}
 
+	if (mohclass->answeredonly && (ast_channel_state(chan) != AST_STATE_UP)) {
+		ast_verb(3, "The channel '%s' is not answered yet. Ignore the moh request.\n", ast_channel_name(chan));
+		return -1;
+	}
+
 	/* If we are using a cached realtime class with files, re-scan the files */
 	if (!var && ast_test_flag(global_flags, MOH_CACHERTCLASSES) && mohclass->realtime && !strcasecmp(mohclass->mode, "files")) {
 		/*

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

Gerrit-Project: asterisk
Gerrit-Branch: 20
Gerrit-Change-Id: I1ab0defa43a29a26ae39f94c623596cf90fddc08
Gerrit-Change-Number: 19224
Gerrit-PatchSet: 1
Gerrit-Owner: sungtae kim <pchero21 at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220912/8dbb2260/attachment-0001.html>


More information about the asterisk-code-review mailing list