[svn-commits] russell: trunk r89263 - /trunk/apps/app_queue.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Nov 13 19:35:29 CST 2007


Author: russell
Date: Tue Nov 13 19:35:28 2007
New Revision: 89263

URL: http://svn.digium.com/view/asterisk?view=rev&rev=89263
Log:
Instead of reserving 800 bytes for periodic announcements, use an array of
ast_str pointers and only alloate space for the strings as needed.

Modified:
    trunk/apps/app_queue.c

Modified: trunk/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_queue.c?view=diff&rev=89263&r1=89262&r2=89263
==============================================================================
--- trunk/apps/app_queue.c (original)
+++ trunk/apps/app_queue.c Tue Nov 13 19:35:28 2007
@@ -94,6 +94,7 @@
 #include "asterisk/stringfields.h"
 #include "asterisk/event.h"
 #include "asterisk/astobj2.h"
+#include "asterisk/strings.h"
 
 enum {
 	QUEUE_STRATEGY_RINGALL = 0,
@@ -402,7 +403,7 @@
 		AST_STRING_FIELD(sound_reporthold);
 	);
 	/*! Sound files: Custom announce, no default */
-	char sound_periodicannounce[MAX_PERIODIC_ANNOUNCEMENTS][80];
+	struct ast_str *sound_periodicannounce[MAX_PERIODIC_ANNOUNCEMENTS];
 	unsigned int dead:1;
 	unsigned int joinempty:2;
 	unsigned int eventwhencalled:2;
@@ -871,9 +872,13 @@
 	ast_string_field_set(q, sound_lessthan, "queue-less-than");
 	ast_string_field_set(q, sound_reporthold, "queue-reporthold");
 
-	ast_copy_string(q->sound_periodicannounce[0], "queue-periodic-announce", sizeof(q->sound_periodicannounce[0]));
-	for (i = 1; i < MAX_PERIODIC_ANNOUNCEMENTS; i++)
-		q->sound_periodicannounce[i][0]='\0';
+	if ((q->sound_periodicannounce[0] = ast_str_create(32)))
+		ast_str_set(&q->sound_periodicannounce[0], 0, "queue-periodic-announce");
+
+	for (i = 1; i < MAX_PERIODIC_ANNOUNCEMENTS; i++) {
+		if (q->sound_periodicannounce[i])
+			ast_str_set(&q->sound_periodicannounce[i], 0, "%s", "");
+	}
 }
 
 static void clear_queue(struct call_queue *q)
@@ -1057,13 +1062,15 @@
 			unsigned int i = 0;
 
 			while ((s = strsep(&buf, ",|"))) {
-				ast_copy_string(q->sound_periodicannounce[i], s, sizeof(q->sound_periodicannounce[i]));
+				if (!q->sound_periodicannounce[i])
+					q->sound_periodicannounce[i] = ast_str_create(16);
+				ast_str_set(&q->sound_periodicannounce[i], 0, s);
 				i++;
 				if (i == MAX_PERIODIC_ANNOUNCEMENTS)
 					break;
 			}
 		} else {
-			ast_copy_string(q->sound_periodicannounce[0], val, sizeof(q->sound_periodicannounce[0]));
+			ast_str_set(&q->sound_periodicannounce[0], 0, val);
 		}
 	} else if (!strcasecmp(param, "periodic-announce-frequency")) {
 		q->periodicannouncefrequency = atoi(val);
@@ -1196,9 +1203,16 @@
 static void destroy_queue(void *obj)
 {
 	struct call_queue *q = obj;
+	int i;
+
 	ast_debug(0, "Queue destructor called for queue '%s'!\n", q->name);
+
 	free_members(q, 1);
 	ast_string_field_free_memory(q);
+	for (i = 0; i < MAX_PERIODIC_ANNOUNCEMENTS; i++) {
+		if (q->sound_periodicannounce[i])
+			free(q->sound_periodicannounce[i]);
+	}
 	ao2_ref(q->members, -1);
 }
 
@@ -2115,12 +2129,14 @@
 	ast_verb(3, "Playing periodic announcement\n");
 
 	/* Check to make sure we have a sound file. If not, reset to the first sound file */
-	if (qe->last_periodic_announce_sound >= MAX_PERIODIC_ANNOUNCEMENTS || ast_strlen_zero(qe->parent->sound_periodicannounce[qe->last_periodic_announce_sound])) {
+	if (qe->last_periodic_announce_sound >= MAX_PERIODIC_ANNOUNCEMENTS || 
+		!qe->parent->sound_periodicannounce[qe->last_periodic_announce_sound] ||
+		ast_strlen_zero(qe->parent->sound_periodicannounce[qe->last_periodic_announce_sound]->str)) {
 		qe->last_periodic_announce_sound = 0;
 	}
 	
 	/* play the announcement */
-	res = play_file(qe->chan, qe->parent->sound_periodicannounce[qe->last_periodic_announce_sound]);
+	res = play_file(qe->chan, qe->parent->sound_periodicannounce[qe->last_periodic_announce_sound]->str);
 
 	if ((res > 0 && !valid_exit(qe, res)) || res < 0)
 		res = 0;




More information about the svn-commits mailing list