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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 24 15:52:27 CDT 2013


Author: mmichelson
Date: Fri May 24 15:52:24 2013
New Revision: 389736

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=389736
Log:
Get feature group configuration working properly.


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=389736&r1=389735&r2=389736
==============================================================================
--- team/mmichelson/features_config/main/features_config.c (original)
+++ team/mmichelson/features_config/main/features_config.c Fri May 24 15:52:24 2013
@@ -157,6 +157,46 @@
 	struct ao2_container *items;
 };
 
+static int featuregroup_hash(const void *obj, int flags)
+{
+	const struct featuregroup *group;
+	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:
+		group = obj;
+		return ast_str_case_hash(group->name);
+	}
+}
+
+static int featuregroup_cmp(void *obj, void *arg, int flags)
+{
+	struct featuregroup *group1 = obj;
+	struct featuregroup *group2;
+	const char *key2;
+
+	switch(flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
+	case OBJ_KEY:
+		key2 = arg;
+		return strcasecmp(group1->name, key2) ? 0 : CMP_MATCH;
+	case OBJ_PARTIAL_KEY:
+		key2 = arg;
+		return strncasecmp(group1->name, key2, strlen(key2)) ? 0 : CMP_MATCH;
+	case OBJ_POINTER:
+		group2 = arg;
+		return strcasecmp(group1->name, group2->name) ? 0 : CMP_MATCH;
+	default:
+		return CMP_STOP;
+	}
+}
+
 static void *featuregroup_find(struct ao2_container *group_container, const char *category)
 {
 	return ao2_find(group_container, category, OBJ_KEY);
@@ -229,7 +269,7 @@
 	.type = ACO_ITEM,
 	.name = "featuregroup",
 	.category_match = ACO_BLACKLIST,
-	.category = "(^general$|^featuremap$|^applicationmap$)",
+	.category = "^(general|featuremap|applicationmap)$",
 	.item_offset = offsetof(struct features_config, featuregroups),
 	.item_alloc = featuregroup_alloc,
 	.item_find = featuregroup_find,
@@ -242,7 +282,7 @@
 
 struct aco_file features_conf = {
 	.filename = "features.conf",
-	.types = ACO_TYPES(&global_option, &featuremap_option, &applicationmap_option),
+	.types = ACO_TYPES(&global_option, &featuremap_option, &applicationmap_option, &featuregroup_option),
 };
 
 AO2_GLOBAL_OBJ_STATIC(globals);
@@ -340,6 +380,9 @@
 			return NULL;
 		}
 	}
+
+	cfg->featuregroups = ao2_container_alloc(11, featuregroup_hash,
+			featuregroup_cmp);
 
 	ao2_ref(cfg, +1);
 	return cfg;
@@ -851,7 +894,7 @@
 		struct ast_variable *var, void *obj)
 {
 	RAII_VAR(struct featuregroup_item *, item, NULL, ao2_cleanup);
-	struct ao2_container *featuregroups = obj;
+	struct featuregroup *group = obj;
 
 	item = ao2_alloc(sizeof(*item), featuregroup_item_destructor);
 	if (!item || ast_string_field_init(item, 32)) {
@@ -861,7 +904,7 @@
 	ast_string_field_set(item, appmap_item_name, var->name);
 	ast_string_field_set(item, dtmf_override, var->value);
 
-	ao2_link(featuregroups, item);
+	ao2_link(group->items, item);
 
 	/* We wait to look up the application map item in the preapply callback */
 
@@ -934,24 +977,26 @@
 	return *err ? CMP_STOP : 0;
 }
 
-static int features_pre_apply_config(void)
-{
-	RAII_VAR(struct features_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
-	int err = 0;
-
-	/* Now that the entire config has been processed, we can check that the featuregroup
-	 * items refer to actual applicationmap items.
-	 */
-
-	ao2_callback_data(cfg->featuregroups, 0, check_featuregroup, &err, cfg->applicationmap);
-
-	return err;
-}
+static int features_pre_apply_config(void);
 
 CONFIG_INFO_CORE("features", cfg_info, globals, features_config_alloc,
 	.files = ACO_FILES(&features_conf),
 	.pre_apply_config = features_pre_apply_config,
 );
+
+static int features_pre_apply_config(void)
+{
+	struct features_config *cfg = aco_pending_config(&cfg_info);
+	int err = 0;
+
+	/* Now that the entire config has been processed, we can check that the featuregroup
+	 * items refer to actual applicationmap items.
+	 */
+
+	ao2_callback_data(cfg->featuregroups, 0, check_featuregroup, &err, cfg->applicationmap);
+
+	return err;
+}
 
 static int feature_read(struct ast_channel *chan, const char *cmd, char *data,
 	       char *buf, size_t len)




More information about the asterisk-commits mailing list