[Asterisk-code-review] musiconhold: Only warn if music class is not found in memory... (asterisk[11])

Walter Doekes asteriskteam at digium.com
Thu Mar 24 07:42:36 CDT 2016


Walter Doekes has uploaded a new change for review.

  https://gerrit.asterisk.org/2455

Change subject: musiconhold: Only warn if music class is not found in memory and database.
......................................................................

musiconhold: Only warn if music class is not found in memory and database.

The log message when a MusicOnHold music class was not found was changed
from debug level to WARNING level in Asterisk 11.19 and 13.5.  For those
using realtime musiconhold, this message is wrong because it warns
before checking the database.

This changeset delays the warning until after the database has been
checked.

Reported-by: Conrad de Wet
ASTERISK-25444 #close

Change-Id: I6cfb2db2f9cfbd2bb3d30566ecae361c4abf6dbf
---
M res/res_musiconhold.c
1 file changed, 21 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/55/2455/1

diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index 1002633..9aa2b6d 100644
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -1357,6 +1357,18 @@
 	return class;
 }
 
+static struct ast_variable *load_realtime_musiconhold(const char *name)
+{
+	struct ast_variable *var = ast_load_realtime("musiconhold", "name", name, SENTINEL);
+	if (!var) {
+		ast_log(LOG_WARNING,
+			"Music on Hold class '%s' not found in memory/database. "
+			"Verify your configuration.\n",
+			name);
+	}
+	return var;
+}
+
 static int local_ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
 {
 	struct mohclass *mohclass = NULL;
@@ -1364,6 +1376,7 @@
 	struct ast_variable *var = NULL;
 	int res = 0;
 	int realtime_possible = ast_check_realtime("musiconhold");
+	int warn_if_not_in_memory = !realtime_possible;
 
 	/* The following is the order of preference for which class to use:
 	 * 1) The channels explicitly set musicclass, which should *only* be
@@ -1377,28 +1390,28 @@
 	 * 4) The default class.
 	 */
 	if (!ast_strlen_zero(ast_channel_musicclass(chan))) {
-		mohclass = get_mohbyname(ast_channel_musicclass(chan), 1, 0);
+		mohclass = get_mohbyname(ast_channel_musicclass(chan), warn_if_not_in_memory, 0);
 		if (!mohclass && realtime_possible) {
-			var = ast_load_realtime("musiconhold", "name", ast_channel_musicclass(chan), SENTINEL);
+			var = load_realtime_musiconhold(ast_channel_musicclass(chan));
 		}
 	}
 	if (!mohclass && !var && !ast_strlen_zero(mclass)) {
-		mohclass = get_mohbyname(mclass, 1, 0);
+		mohclass = get_mohbyname(mclass, warn_if_not_in_memory, 0);
 		if (!mohclass && realtime_possible) {
-			var = ast_load_realtime("musiconhold", "name", mclass, SENTINEL);
+			var = load_realtime_musiconhold(mclass);
 		}
 	}
 	if (!mohclass && !var && !ast_strlen_zero(interpclass)) {
-		mohclass = get_mohbyname(interpclass, 1, 0);
+		mohclass = get_mohbyname(interpclass, warn_if_not_in_memory, 0);
 		if (!mohclass && realtime_possible) {
-			var = ast_load_realtime("musiconhold", "name", interpclass, SENTINEL);
+			var = load_realtime_musiconhold(interpclass);
 		}
 	}
 
 	if (!mohclass && !var) {
-		mohclass = get_mohbyname("default", 1, 0);
+		mohclass = get_mohbyname("default", warn_if_not_in_memory, 0);
 		if (!mohclass && realtime_possible) {
-			var = ast_load_realtime("musiconhold", "name", "default", SENTINEL);
+			var = load_realtime_musiconhold("default");
 		}
 	}
 

-- 
To view, visit https://gerrit.asterisk.org/2455
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6cfb2db2f9cfbd2bb3d30566ecae361c4abf6dbf
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 11
Gerrit-Owner: Walter Doekes <walter+asterisk at wjd.nu>



More information about the asterisk-code-review mailing list