[asterisk-commits] trunk r23250 - /trunk/apps/app_voicemail.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Apr 28 18:05:13 MST 2006


Author: russell
Date: Fri Apr 28 20:05:13 2006
New Revision: 23250

URL: http://svn.digium.com/view/asterisk?rev=23250&view=rev
Log:
- convert the list of zones to use the list macros, and add locking (issue #7027, with mods)

Modified:
    trunk/apps/app_voicemail.c

Modified: trunk/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_voicemail.c?rev=23250&r1=23249&r2=23250&view=diff
==============================================================================
--- trunk/apps/app_voicemail.c (original)
+++ trunk/apps/app_voicemail.c Fri Apr 28 20:05:13 2006
@@ -245,10 +245,10 @@
 };
 
 struct vm_zone {
+	AST_LIST_ENTRY(vm_zone) list;
 	char name[80];
 	char timezone[80];
 	char msg_format[512];
-	struct vm_zone *next;
 };
 
 struct vm_state {
@@ -388,8 +388,7 @@
 static char *app4 = "VMAuthenticate";
 
 static AST_LIST_HEAD_STATIC(users, ast_vm_user);
-struct vm_zone *zones = NULL;
-struct vm_zone *zonesl = NULL;
+static AST_LIST_HEAD_STATIC(zones, vm_zone);
 static int maxsilence;
 static int maxmsg;
 static int silencethreshold = 128;
@@ -1655,9 +1654,12 @@
 	/* Does this user have a timezone specified? */
 	if (!ast_strlen_zero(vmu->zonetag)) {
 		/* Find the zone in the list */
-		for (z = zones; z ; z = z->next)
+		AST_LIST_LOCK(&zones);
+		AST_LIST_TRAVERSE(&zones, z, list) {
 			if (!strcmp(z->name, vmu->zonetag))
 				break;
+		}
+		AST_LIST_UNLOCK(&zones);
 	}
 	ast_localtime(&t, tm, z ? z->timezone : NULL);
 	return tm;
@@ -3592,12 +3594,14 @@
 	if (!ast_strlen_zero(vmu->zonetag)) {
 		/* Find the zone in the list */
 		struct vm_zone *z;
-		for (z = zones; z; z = z->next) {
+		AST_LIST_LOCK(&zones);
+		AST_LIST_TRAVERSE(&zones, z, list) {
 			if (!strcmp(z->name, vmu->zonetag)) {
 				the_zone = z;
 				break;
 			}
 		}
+		AST_LIST_UNLOCK(&zones);
 	}
 
 /* No internal variable parsing for now, so we'll comment it out for the time being */
@@ -5858,22 +5862,26 @@
 
 static int handle_show_voicemail_zones(int fd, int argc, char *argv[])
 {
-	struct vm_zone *zone = zones;
+	struct vm_zone *zone;
 	char *output_format = "%-15s %-20s %-45s\n";
-
-	if (argc != 3) return RESULT_SHOWUSAGE;
-
-	if (zone) {
+	int res = RESULT_SUCCESS;
+
+	if (argc != 3)
+		return RESULT_SHOWUSAGE;
+
+	AST_LIST_LOCK(&zones);
+	if (!AST_LIST_EMPTY(&zones)) {
 		ast_cli(fd, output_format, "Zone", "Timezone", "Message Format");
-		while (zone) {
+		AST_LIST_TRAVERSE(&zones, zone, list) {
 			ast_cli(fd, output_format, zone->name, zone->timezone, zone->msg_format);
-			zone = zone->next;
 		}
 	} else {
 		ast_cli(fd, "There are no voicemail zones currently defined\n");
-		return RESULT_FAILURE;
-	}
-	return RESULT_SUCCESS;
+		res = RESULT_FAILURE;
+	}
+	AST_LIST_UNLOCK(&zones);
+
+	return res;
 }
 
 static char *complete_show_voicemail_users(const char *line, const char *word, int pos, int state)
@@ -5913,7 +5921,7 @@
 static int load_config(void)
 {
 	struct ast_vm_user *cur;
-	struct vm_zone *zcur, *zl;
+	struct vm_zone *zcur;
 	struct ast_config *cfg;
 	char *cat;
 	struct ast_variable *var;
@@ -5950,21 +5958,18 @@
 	int tmpadsi[4];
 
 	cfg = ast_config_load(VOICEMAIL_CONFIG);
+
 	AST_LIST_LOCK(&users);
-	AST_LIST_TRAVERSE_SAFE_BEGIN(&users, cur, list) {
-		AST_LIST_REMOVE_CURRENT(&users, list);
+	while ((cur = AST_LIST_REMOVE_HEAD(&users, list))) {
 		ast_set_flag(cur, VM_ALLOCED);	
 		free_user(cur);
 	}
-	AST_LIST_TRAVERSE_SAFE_END;
-	zcur = zones;
-	while (zcur) {
-		zl = zcur;
-		zcur = zcur->next;
-		free_zone(zl);
-	}
-	zones = NULL;
-	zonesl = NULL;
+
+	AST_LIST_LOCK(&zones);
+	while ((zcur = AST_LIST_REMOVE_HEAD(&zones, list))) 
+		free_zone(zcur);
+	AST_LIST_UNLOCK(&zones);
+
 	memset(ext_pass_cmd, 0, sizeof(ext_pass_cmd));
 
 	if (cfg) {
@@ -6232,14 +6237,9 @@
 									ast_copy_string(z->name, var->name, sizeof(z->name));
 									ast_copy_string(z->timezone, timezone, sizeof(z->timezone));
 									ast_copy_string(z->msg_format, msg_format, sizeof(z->msg_format));
-									z->next = NULL;
-									if (zones) {
-										zonesl->next = z;
-										zonesl = z;
-									} else {
-										zones = z;
-										zonesl = z;
-									}
+									AST_LIST_LOCK(&zones);
+									AST_LIST_INSERT_HEAD(&zones, z, list);
+									AST_LIST_UNLOCK(&zones);
 								} else {
 									ast_log(LOG_WARNING, "Invalid timezone definition at line %d\n", var->lineno);
 									free(z);



More information about the asterisk-commits mailing list