[Asterisk-code-review] res_musiconhold: Add option to not play music on hold on unanswered c... (asterisk[master])
sungtae kim
asteriskteam at digium.com
Sat Aug 13 11:33:45 CDT 2022
sungtae kim has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/18966 )
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, 18 insertions(+), 0 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/66/18966/1
diff --git a/configs/samples/musiconhold.conf.sample b/configs/samples/musiconhold.conf.sample
index 2f60108..f4f909a 100644
--- a/configs/samples/musiconhold.conf.sample
+++ b/configs/samples/musiconhold.conf.sample
@@ -10,6 +10,10 @@
; over a class set by an application (e.g. a musicclass set on a queue).
; Defaults to yes.
+;answeredonly=yes ; Only allow answered channels to have music on hold.
+ ; Enabling this will prevent MOH on unanswered channels.
+ ; (default: "no")
+
; valid mode options:
; files -- read files from a directory in any Asterisk supported
; media format
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..01c9cf8 100644
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -152,6 +152,7 @@
#define MOH_CACHERTCLASSES (1 << 5) /*!< Should we use a separate instance of MOH for each user or not */
#define MOH_ANNOUNCEMENT (1 << 6) /*!< Do we play announcement files between songs on this channel? */
#define MOH_PREFERCHANNELCLASS (1 << 7) /*!< Should queue moh override channel moh */
+#define MOH_ANSWEREDONLY (1 << 8) /*!< Play the moh if the channel answered */
/* Custom astobj2 flag */
#define MOH_NOTDELETED (1 << 30) /*!< Find only records that aren't deleted? */
@@ -1659,6 +1660,13 @@
int warn_if_not_in_memory = !realtime_possible;
const char *classes[] = {NULL, NULL, interpclass, "default"};
+ if (ast_test_flag(global_flags, MOH_ANSWEREDONLY)) {
+ if (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 (ast_test_flag(global_flags, MOH_PREFERCHANNELCLASS)) {
classes[0] = ast_channel_musicclass(chan);
classes[1] = mclass;
@@ -2013,6 +2021,8 @@
ast_set2_flag(global_flags, ast_true(var->value), MOH_CACHERTCLASSES);
} else if (!strcasecmp(var->name, "preferchannelclass")) {
ast_set2_flag(global_flags, ast_true(var->value), MOH_PREFERCHANNELCLASS);
+ } else if (!strcasecmp(var->name, "answeredonly")) {
+ ast_set2_flag(global_flags, ast_true(var->value), MOH_ANSWEREDONLY);
} else {
ast_log(LOG_WARNING, "Unknown option '%s' in [general] section of musiconhold.conf\n", var->name);
}
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/18966
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I1ab0defa43a29a26ae39f94c623596cf90fddc08
Gerrit-Change-Number: 18966
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/20220813/daa9c628/attachment.html>
More information about the asterisk-code-review
mailing list