[asterisk-commits] mmichelson: branch mmichelson/features_config r390025 - /team/mmichelson/feat...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed May 29 10:39:42 CDT 2013


Author: mmichelson
Date: Wed May 29 10:39:39 2013
New Revision: 390025

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=390025
Log:
Prevent duplicate applicationmap entries from being returned when grabbing dynamic features.


Modified:
    team/mmichelson/features_config/main/features_config.c

Modified: team/mmichelson/features_config/main/features_config.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/features_config/main/features_config.c?view=diff&rev=390025&r1=390024&r2=390025
==============================================================================
--- team/mmichelson/features_config/main/features_config.c (original)
+++ team/mmichelson/features_config/main/features_config.c Wed May 29 10:39:39 2013
@@ -45,43 +45,23 @@
 	ast_string_field_free_memory(item);
 }
 
-static int applicationmap_hash(const void *obj, int flags)
-{
-	const struct ast_applicationmap_item *item;
-	const char *key;
-
-	switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
-	case OBJ_KEY:
-		key = obj;
-		return ast_str_case_hash(key);
-	case OBJ_PARTIAL_KEY:
-		ast_assert(0);
-		return 0;
-	case OBJ_POINTER:
-	default:
-		item = obj;
-		return ast_str_case_hash(item->name);
-	}
-}
-
-static int applicationmap_cmp(void *obj, void *arg, int flags)
-{
-	struct ast_applicationmap_item *item1 = obj;
-	struct ast_applicationmap_item *item2;
+static int applicationmap_sort(const void *obj, const void *arg, int flags)
+{
+	const struct ast_applicationmap_item *item1 = obj;
+	const struct ast_applicationmap_item *item2;
 	const char *key2;
 
 	switch(flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
 	case OBJ_KEY:
 		key2 = arg;
-		return strcasecmp(item1->name, key2) ? 0 : CMP_MATCH;
+		return strcasecmp(item1->name, key2);
 	case OBJ_PARTIAL_KEY:
 		key2 = arg;
-		return strncasecmp(item1->name, key2, strlen(key2)) ? 0 : CMP_MATCH;
+		return strncasecmp(item1->name, key2, strlen(key2));
+	default:
 	case OBJ_POINTER:
 		item2 = arg;
-		return strcasecmp(item1->name, item2->name) ? 0 : CMP_MATCH;
-	default:
-		return CMP_STOP;
+		return strcasecmp(item1->name, item2->name);
 	}
 }
 
@@ -343,6 +323,12 @@
 	return cfg;
 }
 
+static struct ao2_container *applicationmap_alloc(void)
+{
+	return ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK,
+			AO2_CONTAINER_ALLOC_OPT_DUPS_REJECT, applicationmap_sort, NULL);
+}
+
 static struct features_config *__features_config_alloc(int allocate_applicationmap)
 {
 	RAII_VAR(struct features_config *, cfg, NULL, ao2_cleanup);
@@ -363,8 +349,7 @@
 	}
 
 	if (allocate_applicationmap) {
-		cfg->applicationmap = ao2_container_alloc(11, applicationmap_hash,
-				applicationmap_cmp);
+		cfg->applicationmap = applicationmap_alloc();
 		if (!cfg->applicationmap) {
 			return NULL;
 		}
@@ -852,8 +837,7 @@
 		return NULL;
 	}
 
-	applicationmap = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, 11,
-			applicationmap_hash, applicationmap_cmp);
+	applicationmap = applicationmap_alloc();
 	if (!applicationmap) {
 		return NULL;
 	}




More information about the asterisk-commits mailing list