[asterisk-commits] twilson: branch twilson/config_work r362136 - in /team/twilson/config_work: a...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Apr 13 22:26:05 CDT 2012


Author: twilson
Date: Fri Apr 13 22:26:01 2012
New Revision: 362136

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=362136
Log:
Rework API naming

Modified:
    team/twilson/config_work/apps/app_skel.c
    team/twilson/config_work/include/asterisk/config_options.h
    team/twilson/config_work/main/asterisk.exports.in
    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=362136&r1=362135&r2=362136
==============================================================================
--- team/twilson/config_work/apps/app_skel.c (original)
+++ team/twilson/config_work/apps/app_skel.c Fri Apr 13 22:26:01 2012
@@ -146,10 +146,11 @@
 
 static int skel_apply_config(void);
 
-static struct ast_config_option_info config_info = {
+static struct aco_info cfg_info = {
 	.module = AST_MODULE,
 	.filename = "app_skel.conf",
 	.apply_config = skel_apply_config,
+	.preload = "pvt3,general",
 };
 
 static void skel_global_config_destructor(void *obj)
@@ -247,7 +248,7 @@
  * \note It is not possible to take the address of a bitfield, therefor all
  * bitfields in the config struct will have to use a custom handler
  */
-static int custom_bitfield_handler(const struct ast_config_option *opt, struct ast_variable *var, void *obj)
+static int custom_bitfield_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
 {
 	struct skel_pvt_config *cfg = obj;
 
@@ -267,13 +268,13 @@
 	void *old;
 	void *array[NUM_GLOBAL_OBJECTS];
 	int i;
-	RAII_VAR(struct ast_config_option_object *, glob, NULL, ao2_cleanup);
-	RAII_VAR(struct ast_config_option_object *, priv, NULL, ao2_cleanup);
-
-	if (!(glob = ao2_find(config_info.objs_container, "global", OBJ_KEY))) {
+	RAII_VAR(struct aco_type *, glob, NULL, ao2_cleanup);
+	RAII_VAR(struct aco_type *, priv, NULL, ao2_cleanup);
+
+	if (!(glob = ao2_find(cfg_info.objs, "global", OBJ_KEY))) {
 		return -1;
 	}
-	if (!(priv = ao2_find(config_info.objs_container, "private", OBJ_KEY))) {
+	if (!(priv = ao2_find(cfg_info.objs, "private", OBJ_KEY))) {
 		return -1;
 	}
 
@@ -286,7 +287,7 @@
 			/* There was an existing config */
 			ao2_ref(old, -1);
 		}
-		/* the "alloc" ref will be cleaned up by the caller */	
+		/* the "alloc" ref will be cleaned up by the caller */
 	}
 
 	return 0;
@@ -495,7 +496,7 @@
 static int reload_module(void)
 {
 	ast_mutex_lock(&reload_lock);
-	if (ast_config_option_parse_config(&config_info, 1)) {
+	if (aco_process_config(&cfg_info, 1)) {
 		ast_mutex_unlock(&reload_lock);
 		return AST_MODULE_LOAD_DECLINE;
 	}
@@ -507,56 +508,56 @@
 static int unload_module(void)
 {
 	ast_cli_unregister_multiple(skel_cli, ARRAY_LEN(skel_cli));
-	ao2_ref(config_info.opts_container, -1);
-	ao2_ref(config_info.objs_container, -1);
+	ao2_ref(cfg_info.opts, -1);
+	ao2_ref(cfg_info.objs, -1);
 	ao2_global_obj_release(global_config);
 	return ast_unregister_application(app);
 }
 
 static int load_module(void)
 {
-	RAII_VAR(struct ast_config_option_object *, global_type, NULL, ao2_cleanup);
-	RAII_VAR(struct ast_config_option_object *, priv_type, NULL, ao2_cleanup);
-
-	if (!(config_info.opts_container = ast_config_option_container_new())) {
+	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 (!(config_info.objs_container = aco_obj_container_new())) {
+	if (!(cfg_info.objs = aco_type_container_new())) {
 		ast_log(LOG_ERROR, "2\n");
 		goto error;
 	}
 
-	if (!(global_type = aco_obj_global_alloc("global", CONTEXT_ALLOW, "general", (aco_obj_alloc) skel_global_alloc))) {
+	if (!(global_type = aco_type_global_alloc("global", CONTEXT_ALLOW, "general", (aco_type_alloc) skel_global_alloc))) {
 		ast_log(LOG_ERROR, "3\n");
 		goto error;
 	}
 
-	if (!(priv_type = aco_obj_private_alloc("private", CONTEXT_DENY, "general", (aco_obj_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", (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_obj_register(config_info.objs_container, global_type);
-	aco_obj_register(config_info.objs_container, priv_type);
+	aco_type_register(cfg_info.objs, global_type);
+	aco_type_register(cfg_info.objs, priv_type);
 
 	/* General Options */
-	ast_config_option_register(config_info.opts_container, "foo", global_type, "booya", OPT_STRINGFIELD_T, struct skel_global_config, 0, foo);
-	ast_config_option_register(config_info.opts_container, "bar", global_type, NULL, OPT_STRINGFIELD_T, struct skel_global_config, 0, bar);
-	ast_config_option_register(config_info.opts_container, "baz", global_type, NULL, OPT_STRINGFIELD_T, struct skel_global_config, 0, baz);
-	ast_config_option_register(config_info.opts_container, "blah", global_type, NULL, OPT_BOOL_T, struct skel_global_config, 1, blah);
-	ast_config_option_register(config_info.opts_container, "bindaddr", global_type, "0.0.0.0:1234", OPT_SOCKADDR_T, struct skel_global_config, PARSE_PORT_REQUIRE, bindaddr);
+	aco_option_register(cfg_info.opts, "foo", global_type, "booya", OPT_STRINGFIELD_T, struct skel_global_config, 0, foo);
+	aco_option_register(cfg_info.opts, "bar", global_type, NULL, OPT_STRINGFIELD_T, struct skel_global_config, 0, bar);
+	aco_option_register(cfg_info.opts, "baz", global_type, NULL, OPT_STRINGFIELD_T, struct skel_global_config, 0, baz);
+	aco_option_register(cfg_info.opts, "blah", global_type, NULL, OPT_BOOL_T, struct skel_global_config, 1, blah);
+	aco_option_register(cfg_info.opts, "bindaddr", global_type, "0.0.0.0:1234", OPT_SOCKADDR_T, struct skel_global_config, PARSE_PORT_REQUIRE, bindaddr);
 
 	/* Private Options */
-	ast_config_option_register(config_info.opts_container, "description", priv_type, NULL, OPT_STRINGFIELD_T, struct skel_pvt_config, 0, description);
-	ast_config_option_register(config_info.opts_container, "allow", priv_type, "ulaw,alaw", OPT_CODEC_T, struct skel_pvt_config, 1, prefs, caps);
-	ast_config_option_register(config_info.opts_container, "permit", priv_type, NULL, OPT_ACL_T, struct skel_pvt_config, 1, permit);
-	ast_config_option_register_custom(config_info.opts_container, "bit1", priv_type, "yes", custom_bitfield_handler, 0);
-	ast_config_option_register_custom(config_info.opts_container, "bit2", priv_type, "no", custom_bitfield_handler, 0);
+	aco_option_register(cfg_info.opts, "description", priv_type, NULL, OPT_STRINGFIELD_T, struct skel_pvt_config, 0, description);
+	aco_option_register(cfg_info.opts, "allow", priv_type, "ulaw,alaw", OPT_CODEC_T, struct skel_pvt_config, 1, prefs, caps);
+	aco_option_register(cfg_info.opts, "permit", priv_type, NULL, OPT_ACL_T, struct skel_pvt_config, 1, permit);
+	aco_option_register_custom(cfg_info.opts, "bit1", priv_type, "yes", custom_bitfield_handler, 0);
+	aco_option_register_custom(cfg_info.opts, "bit2", priv_type, "no", custom_bitfield_handler, 0);
 
 	ast_mutex_lock(&reload_lock);
-	if (ast_config_option_parse_config(&config_info, 0)) {
+	if (aco_process_config(&cfg_info, 0)) {
 		ast_mutex_unlock(&reload_lock);
 		ast_log(LOG_ERROR, "5\n");
 		goto error;
@@ -568,11 +569,11 @@
 		AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
 
 error:
-	if (config_info.opts_container) {
-		ao2_ref(config_info.opts_container, -1);
-	}
-	if (config_info.objs_container) {
-		ao2_ref(config_info.objs_container, -1);
+	if (cfg_info.opts) {
+		ao2_ref(cfg_info.opts, -1);
+	}
+	if (cfg_info.objs) {
+		ao2_ref(cfg_info.objs, -1);
 	}
 	return AST_MODULE_LOAD_DECLINE;
 }

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=362136&r1=362135&r2=362136
==============================================================================
--- team/twilson/config_work/include/asterisk/config_options.h (original)
+++ team/twilson/config_work/include/asterisk/config_options.h Fri Apr 13 22:26:01 2012
@@ -33,42 +33,42 @@
 #include "asterisk/config.h"
 #include "asterisk/astobj2.h"
 
-struct ast_config_option;
-
-enum ast_config_option_object_t {
+struct aco_option;
+
+enum aco_type_t {
 	GLOBAL_OBJ,
 	PRIVATE_OBJ,
 };
 
 /*! \brief Whether a context regex is a blackist or a whitelist */
-enum ast_config_option_context_op {
+enum aco_context_op {
 	CONTEXT_DENY = 0,
 	CONTEXT_ALLOW,
 };
 
-typedef void *(*aco_obj_alloc)(const char *category);
-typedef int (*aco_obj_containers_alloc)(struct ao2_container **newpvts, struct ao2_container **newcfgs);
-typedef void *(*aco_obj_find_or_create_pvt)(const char *context);
-typedef void *(*aco_obj_find_pvt)(struct ao2_container *newcontainer, const char *context);
-typedef int (*aco_obj_post_cfg_init)(void *newcfg);
-typedef int (*aco_obj_prelink)(void *newcfg);
+typedef void *(*aco_type_alloc)(const char *category);
+typedef int (*aco_type_containers_alloc)(struct ao2_container **newpvts, struct ao2_container **newcfgs);
+typedef void *(*aco_type_find_or_create_pvt)(const char *context);
+typedef void *(*aco_type_find_pvt)(struct ao2_container *newcontainer, const char *context);
+typedef int (*aco_type_post_cfg_init)(void *newcfg);
+typedef int (*aco_type_prelink)(void *newcfg);
 
 /* ao2 lookup by context, OBJ_KEY, only access with a global reload lock held */
-struct ast_config_option_object {
+struct aco_type {
 	/* common stuff */
-	enum ast_config_option_object_t type;
+	enum aco_type_t type;
 	const char *name;
 	const char *context;
 	regex_t *regex;
-	enum ast_config_option_context_op context_allow;
-	aco_obj_alloc cfg_alloc;
+	enum aco_context_op context_allow;
+	aco_type_alloc cfg_alloc;
 
 	/* non-global callbacks */
-	aco_obj_containers_alloc containers_alloc; /* required. cfgs required, pvts if non-config-related state */ 
-	aco_obj_find_or_create_pvt find_or_create_pvt; /* required if there is non-config-related state */
-	aco_obj_find_pvt find_pvt; /* required if there is non-config-related state */
-	aco_obj_post_cfg_init post_cfg_init; /*!< Filter global options done if necessary */
-	aco_obj_prelink prelink; /* optional, can be used to do additional checks on a config */
+	aco_type_containers_alloc containers_alloc; /* required. cfgs required, pvts if non-config-related state */
+	aco_type_find_or_create_pvt find_or_create_pvt; /* required if there is non-config-related state */
+	aco_type_find_pvt find_pvt; /* required if there is non-config-related state */
+	aco_type_post_cfg_init post_cfg_init; /*!< Filter global options done if necessary */
+	aco_type_prelink prelink; /* optional, can be used to do additional checks on a config */
 
 	/* global cached object */
 	void *new_global_cfg; /* This is a cache and the reason we need locks */
@@ -78,34 +78,35 @@
 	struct ao2_container *new_cfgs; /* required */
 };
 
-struct ao2_container *aco_obj_container_new(void);
-struct ast_config_option_object *aco_obj_global_alloc(const char *name, enum ast_config_option_context_op op, const char *context, aco_obj_alloc alloc);
-struct ast_config_option_object *aco_obj_private_alloc(const char *name, enum ast_config_option_context_op op, const char *context,
-	aco_obj_alloc alloc, aco_obj_containers_alloc containers_alloc, aco_obj_find_or_create_pvt find_or_create_pvt,
-	aco_obj_find_pvt find_pvt, aco_obj_post_cfg_init post_cfg_init, aco_obj_prelink prelink);
-int aco_obj_register(struct ao2_container *container, struct ast_config_option_object *obj);
+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,
+	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);
 
-struct ast_config_option_info {
+struct aco_info {
 	const char *module;
 	const char *filename;
-	struct ao2_container *opts_container;
-	struct ao2_container *objs_container;
+	const char *preload;
+	struct ao2_container *opts;
+	struct ao2_container *objs;
 	aco_apply_config apply_config;
 };
 
 /*! \brief The option types with default handlers
  *
- * ast_config_option_register takes an option type which is used
+ * aco_option_register takes an option type which is used
  * to look up the handler for that type. Each type requires field
  * names for specific types in the struct being configured. Each
  * option below is commented with the field types, *in the order
- * they must be passed* to ast_config_option_register. The fields
+ * they must be passed* to aco_option_register. The fields
  * are located in the args array in the ast_config_option passed to
  * the default handler function.
  * */
-enum ast_config_option_type {
+enum aco_option_type {
 	OPT_ACL_T,         /*!< fields: struct ast_ha * */
 	OPT_BOOL_T,        /*!< fields: unsigned int */
 	OPT_CODEC_T,       /*!< fields: struct ast_codec pref, struct ast_format_cap * */
@@ -125,10 +126,10 @@
  * \retval 0 Parsing and recording the config value succeeded
  * \retval non-zero Failure. Parsing should stop and no reload applied
  */
-typedef int (*ast_config_option_handler)(const struct ast_config_option *opt, struct ast_variable *var, void *obj);
+typedef int (*aco_option_handler)(const struct aco_option *opt, struct ast_variable *var, void *obj);
 
 /*! \brief Allocate a container to hold config options */
-struct ao2_container *ast_config_option_container_new(void);
+struct ao2_container *aco_option_container_new(void);
 
 /*! \brief Find a config option that can handle the option \a name in \a context
  * \param container The container of options to search
@@ -137,7 +138,7 @@
  *
  * \returns An option or NULL on error
  */
-struct ast_config_option *ast_config_option_find(struct ao2_container *container, const char *name, const char *context);
+struct aco_option *aco_option_find(struct ao2_container *container, const char *name, const char *context);
 
 /*! \brief Completely handle simple configs
  *
@@ -153,7 +154,7 @@
  * \retval 0 Success
  * \retval 1 Failure
  */
-int ast_config_option_parse_config(struct ast_config_option_info *info, int reload);
+int aco_process_config(struct aco_info *info, int reload);
 
 /*! \brief Parse each option defined in a config context
  * \param container The container of options from which to configure \a obj
@@ -164,7 +165,7 @@
  * \retval 0 Success
  * \retval -1 Failure
  */
-int ast_config_parse_category_options(struct ao2_container *container, struct ast_config *cfg, const char *cat, void *obj);
+int aco_process_category_options(struct ao2_container *container, struct ast_config *cfg, const char *cat, void *obj);
 
 /*! \brief Set all default options of \a obj
  * \param container The container of options from which to apply defaults
@@ -174,11 +175,11 @@
  * \retval 0 Success
  * \retval -1 Failure
  */
-int ast_config_option_set_defaults(struct ao2_container *container, const char *context, void *obj);
+int aco_set_defaults(struct ao2_container *container, const char *context, void *obj);
 
 /*! \brief build a config option
  *
- * \note this should probably only be called by one of the ast_config_option_register* macros
+ * \note this should probably only be called by one of the aco_option_register* macros
  *
  * \param name The name of the option
  * \param obj An option object which holds type info about what is being configured
@@ -191,8 +192,8 @@
  *
  * \returns An option on success, NULL on failure
  */
-struct ast_config_option *__ast_config_option_build(const char *name, struct ast_config_option_object *obj,
-	const char *default_val, enum ast_config_option_type type, ast_config_option_handler handler, unsigned int flags, size_t argc, ...);
+struct aco_option *__aco_option_build(const char *name, struct aco_type *obj,
+	const char *default_val, enum aco_option_type type, aco_option_handler handler, unsigned int flags, size_t argc, ...);
 
 /* \brief Register a config option
  * \param container The container to store the registered option in
@@ -205,11 +206,11 @@
  *
  * \returns An option on success, NULL on failure
  */
-#define ast_config_option_register(container, name, obj, default_val, opt_type, struct_type, flags, ...) {\
-	struct ast_config_option *__opt; \
+#define aco_option_register(container, name, obj, default_val, opt_type, struct_type, flags, ...) {\
+	struct aco_option *__opt; \
 	__opt = opt_type == OPT_STRINGFIELD_T ? \
-		__ast_config_option_build(name, obj, default_val, opt_type, NULL, flags, ARGMAP(offsetof, struct_type, __VA_ARGS__, __field_mgr_pool, __field_mgr)) : \
-		__ast_config_option_build(name, obj, default_val, opt_type, NULL, flags, ARGMAP(offsetof, struct_type, __VA_ARGS__)); \
+		__aco_option_build(name, obj, default_val, opt_type, NULL, flags, ARGMAP(offsetof, struct_type, __VA_ARGS__, __field_mgr_pool, __field_mgr)) : \
+		__aco_option_build(name, obj, default_val, opt_type, NULL, flags, ARGMAP(offsetof, struct_type, __VA_ARGS__)); \
 	if (__opt) { \
 		ao2_link(container, __opt); \
 		ao2_ref(__opt, -1); \
@@ -226,8 +227,8 @@
  *
  * \returns An option on success, NULL on failure
  */
-#define ast_config_option_register_custom(container, name, obj, default_val, handler, flags) { \
-	struct ast_config_option *__opt = __ast_config_option_build(name, obj, default_val, OPT_CUSTOM_T, handler, flags, 0); \
+#define aco_option_register_custom(container, name, obj, default_val, handler, flags) { \
+	struct aco_option *__opt = __aco_option_build(name, obj, default_val, OPT_CUSTOM_T, handler, flags, 0); \
 	if (__opt) { \
 		ao2_link(container, __opt); \
 		ao2_ref(__opt, -1); \
@@ -244,7 +245,7 @@
 
 /*! \def ARGMAP(func, func_arg, x, ...)
  * \brief Map \a func(\a func_arg, field) across all fields including \a x
- * 
+ *
  * Example usage:
  *     struct foo {
  *         int a;
@@ -253,9 +254,9 @@
  *     };
  *     ARGMAP(offsetof, struct foo, a, c)
  * produces the string:
- *     2, offsetof(struct foo, a), offsetof(struct foo, b) 
+ *     2, offsetof(struct foo, a), offsetof(struct foo, b)
  * which can be passed as the varargs to some other function
- * 
+ *
  * The macro isn't limited to offsetof, but that is the only purpose for
  * which it has been tested.
  */

Modified: team/twilson/config_work/main/asterisk.exports.in
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/main/asterisk.exports.in?view=diff&rev=362136&r1=362135&r2=362136
==============================================================================
--- team/twilson/config_work/main/asterisk.exports.in (original)
+++ team/twilson/config_work/main/asterisk.exports.in Fri Apr 13 22:26:01 2012
@@ -6,6 +6,7 @@
 		LINKER_SYMBOL_PREFIXpbx_*;
 		LINKER_SYMBOL_PREFIXastman_*;
 		LINKER_SYMBOL_PREFIXaco_*;
+		LINKER_SYMBOL_PREFIX__aco_*;
 		LINKER_SYMBOL_PREFIXao2_*;
 		LINKER_SYMBOL_PREFIX__ao2_*;
 		LINKER_SYMBOL_PREFIXoption_debug;

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=362136&r1=362135&r2=362136
==============================================================================
--- team/twilson/config_work/main/config_options.c (original)
+++ team/twilson/config_work/main/config_options.c Fri Apr 13 22:26:01 2012
@@ -39,36 +39,36 @@
 #define CONFIG_OPT_BUCKETS 53
 #endif /* LOW_MEMORY */
 
-struct ast_config_option {
+struct aco_option {
 	const char *name;
 	const char *default_val;
-	struct ast_config_option_object *obj;
-	enum ast_config_option_type type;
-	enum ast_config_option_context_op context_allow;
-	ast_config_option_handler handler;
+	struct aco_type *obj;
+	enum aco_option_type type;
+	enum aco_context_op context_allow;
+	aco_option_handler handler;
 	unsigned int flags;
 	size_t argc;
-	size_t args[0]; 
+	size_t args[0];
 };
 
 static void config_option_destroy(void *obj)
 {
-	struct ast_config_option *opt = obj;
+	struct aco_option *opt = obj;
 	if (opt->obj) {
 		ao2_ref(opt->obj, -1);
 	}
 }
 
-static int ast_config_option_int_fn(const struct ast_config_option *opt, struct ast_variable *var, void *obj);
-static int ast_config_option_uint_fn(const struct ast_config_option *opt, struct ast_variable *var, void *obj);
-static int ast_config_option_double_fn(const struct ast_config_option *opt, struct ast_variable *var, void *obj);
-static int ast_config_option_sockaddr_fn(const struct ast_config_option *opt, struct ast_variable *var, void *obj);
-static int ast_config_option_stringfield_fn(const struct ast_config_option *opt, struct ast_variable *var, void *obj);
-static int ast_config_option_bool_fn(const struct ast_config_option *opt, struct ast_variable *var, void *obj);
-static int ast_config_option_acl_fn(const struct ast_config_option *opt, struct ast_variable *var, void *obj);
-static int ast_config_option_codec_fn(const struct ast_config_option *opt, struct ast_variable *var, void *obj);
-
-static ast_config_option_handler ast_config_option_default_handler(enum ast_config_option_type type)
+static int ast_config_option_int_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
+static int ast_config_option_uint_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
+static int ast_config_option_double_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
+static int ast_config_option_sockaddr_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
+static int ast_config_option_stringfield_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
+static int ast_config_option_bool_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
+static int ast_config_option_acl_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
+static int ast_config_option_codec_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
+
+static aco_option_handler ast_config_option_default_handler(enum aco_option_type type)
 {
 	switch(type) {
 	case OPT_ACL_T: return ast_config_option_acl_fn;
@@ -107,12 +107,12 @@
 }
 
 /*! \brief build a config option
- * \note this should probably only be called by one of the ast_config_option_register* macros
+ * \note this should probably only be called by one of the aco_option_register* macros
  */
-struct ast_config_option *__ast_config_option_build(const char *name, struct ast_config_option_object *obj,
-	const char *default_val, enum ast_config_option_type type, ast_config_option_handler handler, unsigned int flags, size_t argc, ...)
-{
-	struct ast_config_option *opt;
+struct aco_option *__aco_option_build(const char *name, struct aco_type *obj,
+	const char *default_val, enum aco_option_type type, aco_option_handler handler, unsigned int flags, size_t argc, ...)
+{
+	struct aco_option *opt;
 	va_list ap;
 	int tmp;
 
@@ -154,14 +154,14 @@
 
 static int config_opt_hash(const void *obj, const int flags)
 {
-	const struct ast_config_option *opt = obj;
+	const struct aco_option *opt = obj;
 	const char *name = (flags & OBJ_KEY) ? obj : opt->name;
 	return ast_str_case_hash(name);
 }
 
 static int config_opt_cmp(void *obj, void *arg, int flags)
 {
-	struct ast_config_option *opt1 = obj, *opt2 = arg;
+	struct aco_option *opt1 = obj, *opt2 = arg;
 	const char *name = (flags & OBJ_KEY) ? arg : opt2->name;
 	return strcasecmp(opt1->name, name) ? 0 : CMP_MATCH | CMP_STOP;
 }
@@ -169,24 +169,24 @@
 static int find_option_cb(void *obj, void *arg, void *data, int flags)
 {
 	const char *name = arg, *context = data;
-	struct ast_config_option *match = obj;
+	struct aco_option *match = obj;
 	/* Continue if we don't match on name, or if NOT (regex_matches XOR regex_should_match) */
-	return strcasecmp(name, match->name) || !regexec(match->obj->regex, context, 0, NULL, 0) == !match->obj->context_allow ? 0 : CMP_MATCH | CMP_STOP; 
-}
-
-struct ast_config_option *ast_config_option_find(struct ao2_container *container, const char *name, const char *cat)
+	return strcasecmp(name, match->name) || !regexec(match->obj->regex, context, 0, NULL, 0) == !match->obj->context_allow ? 0 : CMP_MATCH | CMP_STOP;
+}
+
+struct aco_option *aco_option_find(struct ao2_container *container, const char *name, const char *cat)
 {
 	return ao2_callback_data(container, OBJ_KEY, find_option_cb, (void *) name, (void *) cat);
 }
 
-struct ao2_container *ast_config_option_container_new(void)
+struct ao2_container *aco_option_container_new(void)
 {
 	return ao2_container_alloc(CONFIG_OPT_BUCKETS, config_opt_hash, config_opt_cmp);
 }
 
 static int allocate_temp_objects(void *o, void *arg, int flags)
 {
-	struct ast_config_option_object *obj = o;
+	struct aco_type *obj = o;
 	int *error = arg;
 
 	switch (obj->type) {
@@ -208,7 +208,7 @@
 
 static int cleanup_temp_objects(void *obj, void *arg, int flags)
 {
-	struct ast_config_option_object *object = obj;
+	struct aco_type *object = obj;
 	if (!object) {
 		return 0;
 	}
@@ -237,24 +237,24 @@
 
 static int config_opt_obj_context_cmp(void *obj, void *arg, int flags)
 {
-	struct ast_config_option_object *match = obj;
+	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 ast_config_option_object *ast_config_option_object_find(struct ao2_container *container, const char *context)
+	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);
 }
 
-int ast_config_option_parse_config(struct ast_config_option_info *info, int reload)
+int aco_process_config(struct aco_info *info, int reload)
 {
 	struct ast_config *cfg;
 	struct ast_flags cfg_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0, };
 	const char *cat = NULL;
 	int err = 0, res;
-	
+
 	if (ast_strlen_zero(info->filename)) {
 		ast_log(LOG_ERROR, "No filename given, cannot proceed!\n");
 		return -1;
@@ -274,9 +274,9 @@
 		return -1;
 	}
 
-	ao2_callback(info->objs_container, OBJ_NODATA, allocate_temp_objects, &err);
+	ao2_callback(info->objs, OBJ_NODATA, allocate_temp_objects, &err);
 	if (err) {
-		ao2_callback(info->objs_container, OBJ_NODATA, cleanup_temp_objects, NULL);
+		ao2_callback(info->objs, OBJ_NODATA, cleanup_temp_objects, NULL);
 		ast_log(LOG_NOTICE, "1\n");
 		goto error;
 	}
@@ -284,7 +284,7 @@
 	while ((cat = ast_category_browse(cfg, cat))) {
 		RAII_VAR(void *, tmppvt, NULL, ao2_cleanup);
 		RAII_VAR(void *, tmpcfg, NULL, ao2_cleanup);
-		RAII_VAR(struct ast_config_option_object *, obj, ast_config_option_object_find(info->objs_container, cat), ao2_cleanup);
+		RAII_VAR(struct aco_type *, obj, ast_config_option_object_find(info->objs, cat), ao2_cleanup);
 
 		/* Find config object by context, if not found it is an error */
 		if (!obj) {
@@ -294,11 +294,11 @@
 
 		/* if type == GLOBAL_OBJ, set defaults and configure the cached cfg object */
 		if (obj->type == GLOBAL_OBJ && obj->new_global_cfg) {
-			if (ast_config_option_set_defaults(info->opts_container, cat, obj->new_global_cfg)) {
+			if (aco_set_defaults(info->opts, cat, obj->new_global_cfg)) {
 				ast_log(LOG_NOTICE, "3\n");
 				goto error;
 			}
-			if (ast_config_parse_category_options(info->opts_container, cfg, cat, obj->new_global_cfg)) {
+			if (aco_process_category_options(info->opts, cfg, cat, obj->new_global_cfg)) {
 				ast_log(LOG_NOTICE, "4\n");
 				goto error;
 			}
@@ -324,7 +324,7 @@
 				goto error;
 			}
 
-			if (ast_config_option_set_defaults(info->opts_container, cat, tmpcfg)) {
+			if (aco_set_defaults(info->opts, cat, tmpcfg)) {
 				ast_log(LOG_NOTICE, "7\n");
 				goto error;
 			}
@@ -341,7 +341,7 @@
 				goto error;
 			}
 
-			if (ast_config_parse_category_options(info->opts_container, cfg, cat, tmpcfg)) {
+			if (aco_process_category_options(info->opts, cfg, cat, tmpcfg)) {
 				ast_log(LOG_NOTICE, "9\n");
 				goto error;
 			}
@@ -362,25 +362,26 @@
 			}
 		}
 	}
+
 	ast_config_destroy(cfg);
 
 	res = info->apply_config(); /* The module already knows where the objects are */
-	ao2_callback(info->objs_container, OBJ_NODATA, cleanup_temp_objects, NULL);
+	ao2_callback(info->objs, OBJ_NODATA, cleanup_temp_objects, NULL);
 
 	return res;
 
 error:
 	ast_config_destroy(cfg);
-	ao2_callback(info->objs_container, OBJ_NODATA, cleanup_temp_objects, NULL);
+	ao2_callback(info->objs, OBJ_NODATA, cleanup_temp_objects, NULL);
 	return -1;
 }
 
-int ast_config_parse_category_options(struct ao2_container *container, struct ast_config *cfg, const char *cat, void *obj)
+int aco_process_category_options(struct ao2_container *container, struct ast_config *cfg, const char *cat, void *obj)
 {
 	struct ast_variable *var;
 
 	for (var = ast_variable_browse(cfg, cat); var; var = var->next) {
-		RAII_VAR(struct ast_config_option *, opt, ast_config_option_find(container, var->name, cat), ao2_cleanup);
+		RAII_VAR(struct aco_option *, opt, aco_option_find(container, var->name, cat), ao2_cleanup);
 		if (!opt) {
 			ast_log(LOG_WARNING, "Could not find option suitable for category '%s' named '%s'\n", cat, var->name);
 			return -1;
@@ -402,16 +403,16 @@
  */
 static int match_option_by_context(void *obj, void *arg, int flags)
 {
-	struct ast_config_option *match = obj;
+	struct aco_option *match = obj;
 	const char *context = arg;
 
 	return !regexec(match->obj->regex, context, 0, NULL, 0) == !match->obj->context_allow ? 0 : CMP_MATCH;
 }
 
-int ast_config_option_set_defaults(struct ao2_container *container, const char *context, void *obj)
+int aco_set_defaults(struct ao2_container *container, const char *context, void *obj)
 {
 	RAII_VAR(struct ao2_iterator *, iter, NULL, ao2_iterator_cleanup);
-	struct ast_config_option *opt;
+	struct aco_option *opt;
 
 	if (!(iter = ao2_callback(container, OBJ_MULTIPLE, match_option_by_context, (void *) context))) {
 		return -1;
@@ -440,26 +441,26 @@
 
 static int config_opt_obj_hash(const void *obj, const int flags)
 {
-	const struct ast_config_option_object *object = obj;
+	const struct aco_type *object = obj;
 	const char *name = (flags & OBJ_KEY) ? obj : object->name;
 	return ast_str_case_hash(name);
 }
 
 static int config_opt_obj_cmp(void *obj, void *arg, int flags)
 {
-	struct ast_config_option_object *obj1 = obj, *obj2 = arg;
+	struct aco_type *obj1 = obj, *obj2 = arg;
 	const char *name = (flags & OBJ_KEY) ? arg : obj2->name;
 	return strcasecmp(obj1->name, name) ? 0 : CMP_STOP | CMP_MATCH;
 }
 
-struct ao2_container *aco_obj_container_new(void)
+struct ao2_container *aco_type_container_new(void)
 {
 	return ao2_container_alloc(7, config_opt_obj_hash, config_opt_obj_cmp);
 }
 
 static void config_obj_destructor(void *o)
 {
-	struct ast_config_option_object *obj = o;
+	struct aco_type *obj = o;
 	if (obj->regex) {
 		regfree(obj->regex);
 		ast_free(obj->regex);
@@ -467,9 +468,9 @@
 	return;
 }
 
-struct ast_config_option_object *aco_obj_global_alloc(const char *name, enum ast_config_option_context_op op, const char *context, aco_obj_alloc alloc)
-{
-	struct ast_config_option_object *obj;
+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 *obj;
 
 	if (!(obj = ao2_alloc(sizeof(*obj), config_obj_destructor))) {
 		return NULL;
@@ -489,11 +490,11 @@
 	return obj;
 }
 
-struct ast_config_option_object *aco_obj_private_alloc(const char *name, enum ast_config_option_context_op op, const char *context,
-	aco_obj_alloc alloc, aco_obj_containers_alloc containers_alloc, aco_obj_find_or_create_pvt find_or_create_pvt,
-	aco_obj_find_pvt find_pvt, aco_obj_post_cfg_init post_cfg_init, aco_obj_prelink prelink)
-{
-	struct ast_config_option_object *obj;
+struct aco_type *aco_type_private_alloc(const char *name, enum aco_context_op op, const char *context,
+	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)
+{
+	struct aco_type *obj;
 
 	if (!(obj = ao2_alloc(sizeof(*obj), config_obj_destructor))) {
 		return NULL;
@@ -518,29 +519,29 @@
 	return obj;
 }
 
-int aco_obj_register(struct ao2_container *container, struct ast_config_option_object *obj)
+int aco_type_register(struct ao2_container *container, struct aco_type *obj)
 {
 	return !ao2_link(container, obj);
 }
 
 /* default config option handlers */
 
-int ast_config_option_int_fn(const struct ast_config_option *opt, struct ast_variable *var, void *obj) {
+int ast_config_option_int_fn(const struct aco_option *opt, struct ast_variable *var, void *obj) {
 	int *field = (int *)(obj + opt->args[0]);
 	return ast_parse_arg(var->value, PARSE_INT32 | opt->flags, field);
 }
 
-int ast_config_option_uint_fn(const struct ast_config_option *opt, struct ast_variable *var, void *obj) {
+int ast_config_option_uint_fn(const struct aco_option *opt, struct ast_variable *var, void *obj) {
 	unsigned int *field = (unsigned int *)(obj + opt->args[0]);
 	return ast_parse_arg(var->value, PARSE_UINT32 | opt->flags, field);
 }
 
-int ast_config_option_double_fn(const struct ast_config_option *opt, struct ast_variable *var, void *obj) {
+int ast_config_option_double_fn(const struct aco_option *opt, struct ast_variable *var, void *obj) {
 	double *field = (double *)(obj + opt->args[0]);
 	return ast_parse_arg(var->value, PARSE_DOUBLE | opt->flags, field);
 }
 
-int ast_config_option_acl_fn(const struct ast_config_option *opt, struct ast_variable *var, void *obj) {
+int ast_config_option_acl_fn(const struct aco_option *opt, struct ast_variable *var, void *obj) {
 	struct ast_ha **ha = (struct ast_ha **)(obj + opt->args[0]);
 	int error = 0;
 	*ha = ast_append_ha(var->name, var->value, *ha, &error);
@@ -548,14 +549,14 @@
 }
 
 /* opt->args[0] = struct ast_codec_pref, opt->args[1] struct ast_format_cap * */
-int ast_config_option_codec_fn(const struct ast_config_option *opt, struct ast_variable *var, void *obj) {
+int ast_config_option_codec_fn(const struct aco_option *opt, struct ast_variable *var, void *obj) {
 	struct ast_codec_pref *pref = (struct ast_codec_pref *)(obj + opt->args[0]);
 	struct ast_format_cap **cap = (struct ast_format_cap **)(obj + opt->args[1]);
 	return ast_parse_allow_disallow(pref, *cap, var->value, opt->flags);
 }
 
 /* opt->args[0] = ast_string_field,  opt->args[1] = field_mgr_pool, opt->args[2] = field_mgri */
-int ast_config_option_stringfield_fn(const struct ast_config_option *opt, struct ast_variable *var, void *obj)
+int ast_config_option_stringfield_fn(const struct aco_option *opt, struct ast_variable *var, void *obj)
 {
 	ast_string_field *field = (const char **)(obj + opt->args[0]);
 	struct ast_string_field_pool **pool = (struct ast_string_field_pool **)(obj + opt->args[1]);
@@ -564,14 +565,14 @@
 	return 0;
 }
 
-int ast_config_option_bool_fn(const struct ast_config_option *opt, struct ast_variable *var, void *obj)
+int ast_config_option_bool_fn(const struct aco_option *opt, struct ast_variable *var, void *obj)
 {
 	unsigned int *field = (unsigned int *)(obj + opt->args[0]);
 	*field = opt->flags ? ast_true(var->value) : ast_false(var->value);
 	return 0;
 }
 
-int ast_config_option_sockaddr_fn(const struct ast_config_option *opt, struct ast_variable *var, void *obj)
+int ast_config_option_sockaddr_fn(const struct aco_option *opt, struct ast_variable *var, void *obj)
 {
 	struct ast_sockaddr *field = (struct ast_sockaddr *)(obj + opt->args[0]);
 	return ast_parse_arg(var->value, PARSE_ADDR | opt->flags, field);




More information about the asterisk-commits mailing list