[asterisk-commits] wdoekes: trunk r423065 - in /trunk: ./ configs/samples/ res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Sep 14 10:42:09 CDT 2014


Author: wdoekes
Date: Sun Sep 14 10:41:58 2014
New Revision: 423065

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=423065
Log:
musiconhold: Add sort=randstart, and deprecate old stuff.

- adds sort=randstart (next to sort=, sort=random, sort=alpha)
- combines duplicate moh option parsing code into a single function
- adds deprecationwarnings for application=r to sort randomly
- adds deprecationwarnings for random=yes to sort randomly
- removes invisible code that was supposed to stay until 1.8 

The sort=randstart works like sort=alpha, except we start at a random
position.

Review: https://reviewboard.asterisk.org/r/3991/

Modified:
    trunk/CHANGES
    trunk/configs/samples/musiconhold.conf.sample
    trunk/res/res_musiconhold.c

Modified: trunk/CHANGES
URL: http://svnview.digium.com/svn/asterisk/trunk/CHANGES?view=diff&rev=423065&r1=423064&r2=423065
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Sun Sep 14 10:41:58 2014
@@ -21,6 +21,7 @@
    ipaddress to bind the rtpengine too.  For example, chan_sip might bind
    to eth0 (10.0.0.2) but rtpengine to eth1 (192.168.1.10).
 
+
 Functions
 ------------------
 
@@ -28,6 +29,16 @@
 ------------------
  * Added CHANNEL(onhold) item that returns 1 (onhold) and 0 (not-onhold) for
    the hold status of a channel.
+
+
+Resources
+------------------
+
+res_musiconhold
+------------------
+ * Added sort=randstart to the sort options. It sorts the files by name and
+   then chooses the first file to play at random.
+
 
 ------------------------------------------------------------------------------
 --- Functionality changes from Asterisk 12 to Asterisk 13 --------------------

Modified: trunk/configs/samples/musiconhold.conf.sample
URL: http://svnview.digium.com/svn/asterisk/trunk/configs/samples/musiconhold.conf.sample?view=diff&rev=423065&r1=423064&r2=423065
==============================================================================
--- trunk/configs/samples/musiconhold.conf.sample (original)
+++ trunk/configs/samples/musiconhold.conf.sample Sun Sep 14 10:41:58 2014
@@ -57,13 +57,16 @@
 ;               ; be played to them. Also, if using modes that Asterisk
 ;               ; controls the playlist for (files, mp3, etc), the same
 ;               ; sound will also be played between MOH songs.
-;sort=random    ; Sort the files in random order
+;sort=random    ; Sort the files in random order. Other sort options are:
+;               ; 'alpha' and 'randstart'. If 'alpha', the files are sorted
+;               ; 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.
 
 ;[native-alphabetical]
 ;mode=files
 ;directory=moh
-;sort=alpha     ; Sort the files in alphabetical order.  If this option is
-;               ; not specified, the sort order is undefined.
+;sort=alpha     ; Sort the files in alphabetical order.
 
 ; =========
 ; Other (non-native) playback methods

Modified: trunk/res/res_musiconhold.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_musiconhold.c?view=diff&rev=423065&r1=423064&r2=423065
==============================================================================
--- trunk/res/res_musiconhold.c (original)
+++ trunk/res/res_musiconhold.c Sun Sep 14 10:41:58 2014
@@ -148,6 +148,8 @@
 #define MOH_CUSTOM		(1 << 2)
 #define MOH_RANDOMIZE		(1 << 3)
 #define MOH_SORTALPHA		(1 << 4)
+#define MOH_RANDSTART		(MOH_RANDOMIZE | MOH_SORTALPHA) /*!< Sorted but start at random position */
+#define MOH_SORTMODE		(3 << 3)
 
 #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? */
@@ -202,6 +204,7 @@
 #define MPG_123 "/usr/bin/mpg123"
 #define MAX_MP3S 256
 
+static void moh_parse_options(struct ast_variable *var, struct mohclass *mohclass);
 static int reload(void);
 
 #define mohclass_ref(class,string)   (ao2_t_ref((class), +1, (string)), class)
@@ -335,7 +338,7 @@
 		/* If a specific file has been saved confirm it still exists and that it is still valid */
 		state->pos = state->save_pos;
 		state->save_pos = -1;
-	} else if (ast_test_flag(state->class, MOH_RANDOMIZE)) {
+	} else if (ast_test_flag(state->class, MOH_SORTMODE) == MOH_RANDOMIZE) {
 		/* Get a random file and ensure we can open it */
 		for (tries = 0; tries < 20; tries++) {
 			state->pos = ast_random() % state->class->total_files;
@@ -1031,6 +1034,44 @@
 	.digit    = moh_handle_digit,
 };
 
+static void moh_parse_options(struct ast_variable *var, struct mohclass *mohclass)
+{
+	for (; var; var = var->next) {
+		if (!strcasecmp(var->name, "name")) {
+			ast_copy_string(mohclass->name, var->value, sizeof(mohclass->name));
+		} else if (!strcasecmp(var->name, "mode")) {
+			ast_copy_string(mohclass->mode, var->value, sizeof(mohclass->mode));
+		} else if (!strcasecmp(var->name, "directory")) {
+			ast_copy_string(mohclass->dir, var->value, sizeof(mohclass->dir));
+		} else if (!strcasecmp(var->name, "application")) {
+			ast_copy_string(mohclass->args, var->value, sizeof(mohclass->args));
+		} else if (!strcasecmp(var->name, "digit") && (isdigit(*var->value) || strchr("*#", *var->value))) {
+			mohclass->digit = *var->value;
+		} else if (!strcasecmp(var->name, "random")) {
+			static int deprecation_warning = 0;
+			if (!deprecation_warning) {
+				ast_log(LOG_WARNING, "Music on hold 'random' setting is deprecated in 14.  Please use 'sort=random' instead.\n");
+				deprecation_warning = 1;
+			}
+			ast_set2_flag(mohclass, ast_true(var->value), MOH_RANDOMIZE);
+		} else if (!strcasecmp(var->name, "sort")) {
+			if (!strcasecmp(var->value, "random")) {
+				ast_set_flag(mohclass, MOH_RANDOMIZE);
+			} else if (!strcasecmp(var->value, "alpha")) {
+				ast_set_flag(mohclass, MOH_SORTALPHA);
+			} else if (!strcasecmp(var->value, "randstart")) {
+				ast_set_flag(mohclass, MOH_RANDSTART);
+			}
+		} else if (!strcasecmp(var->name, "format")) {
+			mohclass->format = ast_format_cache_get(var->value);
+			if (!mohclass->format) {
+				ast_log(LOG_WARNING, "Unknown format '%s' -- defaulting to SLIN\n", var->value);
+				mohclass->format = ao2_bump(ast_format_slin);
+			}
+               }
+       }
+}
+
 static int moh_add_file(struct mohclass *class, const char *filepath)
 {
 	if (!class->allowed_files) {
@@ -1398,36 +1439,12 @@
 	 * above guarantees that if var is non-NULL, then mohclass must be NULL.
 	 */
 	if (var) {
-		struct ast_variable *tmp = NULL;
-
 		if ((mohclass = moh_class_malloc())) {
 			mohclass->realtime = 1;
-			for (tmp = var; tmp; tmp = tmp->next) {
-				if (!strcasecmp(tmp->name, "name"))
-					ast_copy_string(mohclass->name, tmp->value, sizeof(mohclass->name));
-				else if (!strcasecmp(tmp->name, "mode"))
-					ast_copy_string(mohclass->mode, tmp->value, sizeof(mohclass->mode)); 
-				else if (!strcasecmp(tmp->name, "directory"))
-					ast_copy_string(mohclass->dir, tmp->value, sizeof(mohclass->dir));
-				else if (!strcasecmp(tmp->name, "application"))
-					ast_copy_string(mohclass->args, tmp->value, sizeof(mohclass->args));
-				else if (!strcasecmp(tmp->name, "digit") && (isdigit(*tmp->value) || strchr("*#", *tmp->value)))
-					mohclass->digit = *tmp->value;
-				else if (!strcasecmp(tmp->name, "random"))
-					ast_set2_flag(mohclass, ast_true(tmp->value), MOH_RANDOMIZE);
-				else if (!strcasecmp(tmp->name, "sort") && !strcasecmp(tmp->value, "random"))
-					ast_set_flag(mohclass, MOH_RANDOMIZE);
-				else if (!strcasecmp(tmp->name, "sort") && !strcasecmp(tmp->value, "alpha")) 
-					ast_set_flag(mohclass, MOH_SORTALPHA);
-				else if (!strcasecmp(tmp->name, "format")) {
-					mohclass->format = ast_format_cache_get(tmp->value);
-					if (!mohclass->format) {
-						ast_log(LOG_WARNING, "Unknown format '%s' -- defaulting to SLIN\n", tmp->value);
-						mohclass->format = ao2_bump(ast_format_slin);
-					}
-				}
-			}
+
+			moh_parse_options(var, mohclass);
 			ast_variables_destroy(var);
+
 			if (ast_strlen_zero(mohclass->dir)) {
 				if (!strcasecmp(mohclass->mode, "custom")) {
 					strcpy(mohclass->dir, "nodir");
@@ -1475,8 +1492,14 @@
 						mohclass = mohclass_unref(mohclass, "unreffing potential mohclass (moh_scan_files failed)");
 						return -1;
 					}
-					if (strchr(mohclass->args, 'r'))
+					if (strchr(mohclass->args, 'r')) {
+						static int deprecation_warning = 0;
+						if (!deprecation_warning) {
+							ast_log(LOG_WARNING, "Music on hold 'application=r' setting is deprecated in 14.  Please use 'sort=random' instead.\n");
+							deprecation_warning = 1;
+						}
 						ast_set_flag(mohclass, MOH_RANDOMIZE);
+					}
 				} else if (!strcasecmp(mohclass->mode, "mp3") || !strcasecmp(mohclass->mode, "mp3nb") || !strcasecmp(mohclass->mode, "quietmp3") || !strcasecmp(mohclass->mode, "quietmp3nb") || !strcasecmp(mohclass->mode, "httpmp3") || !strcasecmp(mohclass->mode, "custom")) {
 
 					if (!strcasecmp(mohclass->mode, "custom"))
@@ -1722,43 +1745,15 @@
 				}
 			}
 		}
-		/* These names were deprecated in 1.4 and should not be used until after the next major release. */
-		if (!strcasecmp(cat, "classes") || !strcasecmp(cat, "moh_files") || 
-				!strcasecmp(cat, "general")) {
-			continue;
-		}
 
 		if (!(class = moh_class_malloc())) {
 			break;
 		}
 
+		moh_parse_options(ast_variable_browse(cfg, cat), class);
+		/* For compatibility with the past, we overwrite any name=name
+		 * with the context [name]. */
 		ast_copy_string(class->name, cat, sizeof(class->name));
-		for (var = ast_variable_browse(cfg, cat); var; var = var->next) {
-			if (!strcasecmp(var->name, "mode")) {
-				ast_copy_string(class->mode, var->value, sizeof(class->mode));
-			} else if (!strcasecmp(var->name, "directory")) {
-				ast_copy_string(class->dir, var->value, sizeof(class->dir));
-			} else if (!strcasecmp(var->name, "application")) {
-				ast_copy_string(class->args, var->value, sizeof(class->args));
-			} else if (!strcasecmp(var->name, "announcement")) {
-				ast_copy_string(class->announcement, var->value, sizeof(class->announcement));
-				ast_set_flag(class, MOH_ANNOUNCEMENT);
-			} else if (!strcasecmp(var->name, "digit") && (isdigit(*var->value) || strchr("*#", *var->value))) {
-				class->digit = *var->value;
-			} else if (!strcasecmp(var->name, "random")) {
-				ast_set2_flag(class, ast_true(var->value), MOH_RANDOMIZE);
-			} else if (!strcasecmp(var->name, "sort") && !strcasecmp(var->value, "random")) {
-				ast_set_flag(class, MOH_RANDOMIZE);
-			} else if (!strcasecmp(var->name, "sort") && !strcasecmp(var->value, "alpha")) {
-				ast_set_flag(class, MOH_SORTALPHA);
-			} else if (!strcasecmp(var->name, "format")) {
-				class->format = ast_format_cache_get(var->value);
-				if (!class->format) {
-					ast_log(LOG_WARNING, "Unknown format '%s' -- defaulting to SLIN\n", var->value);
-					class->format = ao2_bump(ast_format_slin);
-				}
-			}
-		}
 
 		if (ast_strlen_zero(class->dir)) {
 			if (!strcasecmp(class->mode, "custom")) {




More information about the asterisk-commits mailing list