[asterisk-commits] russell: trunk r84168 - in /trunk: configs/ res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Oct 1 09:43:57 CDT 2007


Author: russell
Date: Mon Oct  1 09:43:56 2007
New Revision: 84168

URL: http://svn.digium.com/view/asterisk?view=rev&rev=84168
Log:
Add a new option for files-based music on hold to ensure that the sort order
of the files is alphabetical.

(closes issue #10855)
Reported by: jamesgolovich
Patches: 
      asterisk-mohsortalpha.diff.txt uploaded by jamesgolovich (license 176)

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

Modified: trunk/configs/musiconhold.conf.sample
URL: http://svn.digium.com/view/asterisk/trunk/configs/musiconhold.conf.sample?view=diff&rev=84168&r1=84167&r2=84168
==============================================================================
--- trunk/configs/musiconhold.conf.sample (original)
+++ trunk/configs/musiconhold.conf.sample Mon Oct  1 09:43:56 2007
@@ -39,11 +39,16 @@
 ;[native-random]
 ;mode=files
 ;directory=/var/lib/asterisk/moh
-;random=yes     ; Play the files in a random order
 ;digit=#        ; If this option is set for a class, then when callers are
 ;               ; listening to music on hold, they can press this digit, and
 ;               ; they will switch to listening to this music class.
+;sort=random    ; Sort the files in random order
 
+;[native-alphabetical]
+;mode=files
+;directory=/var/lib/asterisk/moh
+;sort=alpha     ; Sort the files in alphabetical order.  If this option is
+;               ; not specified, the sort order is undefined.
 
 ; =========
 ; Other (non-native) playback methods

Modified: trunk/res/res_musiconhold.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_musiconhold.c?view=diff&rev=84168&r1=84167&r2=84168
==============================================================================
--- trunk/res/res_musiconhold.c (original)
+++ trunk/res/res_musiconhold.c Mon Oct  1 09:43:56 2007
@@ -125,6 +125,7 @@
 #define MOH_SINGLE		(1 << 1)
 #define MOH_CUSTOM		(1 << 2)
 #define MOH_RANDOMIZE		(1 << 3)
+#define MOH_SORTALPHA		(1 << 4)
 
 struct mohclass {
 	char name[MAX_MUSICCLASS];
@@ -810,6 +811,16 @@
 	return 0;
 }
 
+static int moh_sort_compare(const void *i1, const void *i2)
+{
+	char *s1, *s2;
+
+	s1 = ((char **)i1)[0];
+	s2 = ((char **)i2)[0];
+
+	return strcasecmp(s1, s2);
+}
+
 static int moh_scan_files(struct mohclass *class) {
 
 	DIR *files_DIR;
@@ -871,6 +882,8 @@
 
 	closedir(files_DIR);
 	chdir(path);
+	if (ast_test_flag(class, MOH_SORTALPHA))
+		qsort(&class->filearray[0], class->total_files, sizeof(char *), moh_sort_compare);
 	return class->total_files;
 }
 
@@ -1061,6 +1074,10 @@
 					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_getformatbyname(var->value);
 					if (!class->format) {




More information about the asterisk-commits mailing list