[svn-commits] twilson: branch twilson/config_work r362138 - in /team/twilson/config_work: a...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sat Apr 14 09:12:49 CDT 2012


Author: twilson
Date: Sat Apr 14 09:12:44 2012
New Revision: 362138

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=362138
Log:
Add field matching, aco_info_init/destroy

Modified:
    team/twilson/config_work/apps/app_skel.c
    team/twilson/config_work/include/asterisk/config_options.h
    team/twilson/config_work/main/config_options.c

Modified: team/twilson/config_work/apps/app_skel.c
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/apps/app_skel.c?view=diff&rev=362138&r1=362137&r2=362138
==============================================================================
--- team/twilson/config_work/apps/app_skel.c (original)
+++ team/twilson/config_work/apps/app_skel.c Sat Apr 14 09:12:44 2012
@@ -508,8 +508,7 @@
 static int unload_module(void)
 {
 	ast_cli_unregister_multiple(skel_cli, ARRAY_LEN(skel_cli));
-	ao2_ref(cfg_info.opts, -1);
-	ao2_ref(cfg_info.objs, -1);
+	aco_info_destroy(&cfg_info);
 	ao2_global_obj_release(global_config);
 	return ast_unregister_application(app);
 }
@@ -519,13 +518,7 @@
 	RAII_VAR(struct aco_type *, global_type, NULL, ao2_cleanup);
 	RAII_VAR(struct aco_type *, priv_type, NULL, ao2_cleanup);
 
-	if (!(cfg_info.opts = aco_option_container_new())) {
-		ast_log(LOG_ERROR, "1\n");
-		goto error;
-	}
-
-	if (!(cfg_info.objs = aco_type_container_new())) {
-		ast_log(LOG_ERROR, "2\n");
+	if (aco_info_init(&cfg_info)) {
 		goto error;
 	}
 
@@ -534,13 +527,13 @@
 		goto error;
 	}
 
-	if (!(priv_type = aco_type_private_alloc("private", CONTEXT_DENY, "general", (aco_type_alloc) skel_pvt_cfg_alloc, skel_containers_alloc, skel_find_or_create_pvt, skel_find_pvt, NULL, NULL))) {
+	if (!(priv_type = aco_type_private_alloc("private", CONTEXT_DENY, "general", NULL, NULL, (aco_type_alloc) skel_pvt_cfg_alloc, skel_containers_alloc, skel_find_or_create_pvt, skel_find_pvt, NULL, NULL))) {
 		ast_log(LOG_ERROR, "4\n");
 		goto error;
 	}
 
-	aco_type_register(cfg_info.objs, global_type);
-	aco_type_register(cfg_info.objs, priv_type);
+	aco_type_register(&cfg_info, global_type);
+	aco_type_register(&cfg_info, priv_type);
 
 	/* General Options */
 	aco_option_register(cfg_info.opts, "foo", global_type, "booya", OPT_STRINGFIELD_T, struct skel_global_config, 0, foo);

Modified: team/twilson/config_work/include/asterisk/config_options.h
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/include/asterisk/config_options.h?view=diff&rev=362138&r1=362137&r2=362138
==============================================================================
--- team/twilson/config_work/include/asterisk/config_options.h (original)
+++ team/twilson/config_work/include/asterisk/config_options.h Sat Apr 14 09:12:44 2012
@@ -59,6 +59,8 @@
 	enum aco_type_t type;
 	const char *name;
 	const char *context;
+	const char *matchfield;
+	const char *matchvalue;
 	regex_t *regex;
 	enum aco_context_op context_allow;
 	aco_type_alloc cfg_alloc;
@@ -80,10 +82,9 @@
 
 struct ao2_container *aco_type_container_new(void);
 struct aco_type *aco_type_global_alloc(const char *name, enum aco_context_op op, const char *context, aco_type_alloc alloc);
-struct aco_type *aco_type_private_alloc(const char *name, enum aco_context_op op, const char *context,
+struct aco_type *aco_type_private_alloc(const char *name, enum aco_context_op op, const char *context, const char *matchfield, const char *matchvalue,
 	aco_type_alloc alloc, aco_type_containers_alloc containers_alloc, aco_type_find_or_create_pvt find_or_create_pvt,
 	aco_type_find_pvt find_pvt, aco_type_post_cfg_init post_cfg_init, aco_type_prelink prelink);
-int aco_type_register(struct ao2_container *container, struct aco_type *obj);
 
 typedef int (*aco_apply_config)(void);
 
@@ -95,6 +96,10 @@
 	aco_apply_config apply_config;
 	const char *preload[]; /* Use a sentinel! */
 };
+
+int aco_info_init(struct aco_info *info);
+void aco_info_destroy(struct aco_info *info);
+int aco_type_register(struct aco_info *info, struct aco_type *obj);
 
 /*! \brief The option types with default handlers
  *

Modified: team/twilson/config_work/main/config_options.c
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/main/config_options.c?view=diff&rev=362138&r1=362137&r2=362138
==============================================================================
--- team/twilson/config_work/main/config_options.c (original)
+++ team/twilson/config_work/main/config_options.c Sat Apr 14 09:12:44 2012
@@ -235,17 +235,35 @@
 	return 0;
 }
 
-static int config_opt_obj_context_cmp(void *obj, void *arg, int flags)
+static int config_opt_obj_context_cmp(void *obj, void *arg, void *data, int flags)
 {
 	struct aco_type *match = obj;
 	const char *context = arg;
-
-	return !regexec(match->regex, context, 0, NULL, 0) == !match->context_allow ? 0 : CMP_MATCH | CMP_STOP;
-}
-
-static struct aco_type *ast_config_option_object_find(struct ao2_container *container, const char *context)
-{
-	return ao2_callback(container, 0, config_opt_obj_context_cmp, (void *) context);
+	struct ast_config *cfg = data;
+	const char *val;
+
+	/* First make sure we are an object that can service this context */
+	if (!regexec(match->regex, context, 0, NULL, 0) == !match->context_allow) {
+		return 0;
+	}
+
+	/* Then, see if we need to match a particular field */
+	if (!ast_strlen_zero(match->matchfield) && !ast_strlen_zero(match->matchvalue)) {
+		if (!(val = ast_variable_retrieve(cfg, context, match->matchfield))) {
+			ast_log(LOG_ERROR, "Required match field '%s' not found\n", match->matchfield);
+			return CMP_STOP;
+		}
+		if (strcasecmp(val, match->matchvalue)) {
+			return 0;
+		}
+	}
+
+	return CMP_MATCH | CMP_STOP;
+}
+
+static struct aco_type *internal_aco_type_find(struct ao2_container *container, struct ast_config *cfg, const char *context)
+{
+	return ao2_callback_data(container, 0, config_opt_obj_context_cmp, (void *) context, (void *) cfg);
 }
 
 static int is_preload(struct aco_info *info, const char *cat)
@@ -267,7 +285,7 @@
 static int process_category(struct ast_config *cfg, struct aco_info *info, const char *cat, int preload) {
 	RAII_VAR(void *, tmppvt, NULL, ao2_cleanup);
 	RAII_VAR(void *, tmpcfg, NULL, ao2_cleanup);
-	RAII_VAR(struct aco_type *, obj, ast_config_option_object_find(info->objs, cat), ao2_cleanup);
+	RAII_VAR(struct aco_type *, obj, internal_aco_type_find(info->objs, cfg, cat), ao2_cleanup);
 
 	/* Skip preloaded categories if we aren't preloading */
 	if (!preload && is_preload(info, cat)) {
@@ -276,7 +294,7 @@
 
 	/* Find config object by context, if not found it is an error */
 	if (!obj) {
-		ast_log(LOG_NOTICE, "2\n");
+		ast_log(LOG_ERROR, "Could not find config type for category '%s' in '%s'\n", cat, info->filename);
 		return -1;
 	}
 
@@ -430,6 +448,27 @@
 	return 0;
 }
 
+int aco_info_init(struct aco_info *info)
+{
+	if (!(info->opts = aco_option_container_new())) {
+		return -1;
+	}
+	if (!(info->objs = aco_type_container_new())) {
+		return -1;
+	}
+	return 0;
+}
+
+void aco_info_destroy(struct aco_info *info)
+{
+	if (info->opts) {
+		ao2_ref(info->opts, -1);
+	}
+	if (info->objs) {
+		ao2_ref(info->objs, -1);
+	}
+}
+
 /*! \brief match for anything where the context passes (or fails if !context_allow) the context regex
  */
 static int match_option_by_context(void *obj, void *arg, int flags)
@@ -521,7 +560,7 @@
 	return obj;
 }
 
-struct aco_type *aco_type_private_alloc(const char *name, enum aco_context_op op, const char *context,
+struct aco_type *aco_type_private_alloc(const char *name, enum aco_context_op op, const char *context, const char *matchfield, const char *matchvalue,
 	aco_type_alloc alloc, aco_type_containers_alloc containers_alloc, aco_type_find_or_create_pvt find_or_create_pvt,
 	aco_type_find_pvt find_pvt, aco_type_post_cfg_init post_cfg_init, aco_type_prelink prelink)
 {
@@ -541,6 +580,8 @@
 	obj->context_allow = op;
 	obj->cfg_alloc = alloc;
 	obj->context = context;
+	obj->matchfield = matchfield;
+	obj->matchvalue = matchvalue;
 	obj->containers_alloc = containers_alloc;
 	obj->find_or_create_pvt = find_or_create_pvt;
 	obj->find_pvt = find_pvt;
@@ -550,9 +591,9 @@
 	return obj;
 }
 
-int aco_type_register(struct ao2_container *container, struct aco_type *obj)
-{
-	return !ao2_link(container, obj);
+int aco_type_register(struct aco_info *info, struct aco_type *obj)
+{
+	return !ao2_link(info->objs, obj);
 }
 
 /* default config option handlers */




More information about the svn-commits mailing list