[asterisk-commits] twilson: branch twilson/config_work r366965 - in /team/twilson/config_work: a...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri May 18 11:12:57 CDT 2012
Author: twilson
Date: Fri May 18 11:12:53 2012
New Revision: 366965
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=366965
Log:
Get rid of the the confusing use of "private" and "config"
Use "item" and "item state"
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
team/twilson/config_work/main/udptl.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=366965&r1=366964&r2=366965
==============================================================================
--- team/twilson/config_work/apps/app_skel.c (original)
+++ team/twilson/config_work/apps/app_skel.c Fri May 18 11:12:53 2012
@@ -111,11 +111,11 @@
struct ast_sockaddr bindaddr;
};
-struct skel_pvt {
+struct skel_item_state {
size_t non_config_state;
};
-struct skel_pvt_config {
+struct skel_item {
AST_DECLARE_STRING_FIELDS(
AST_STRING_FIELD(name);
AST_STRING_FIELD(description);
@@ -125,34 +125,34 @@
struct ast_ha *permit;
unsigned int bit1:1;
unsigned int bit2:1;
- struct skel_pvt *pvt;
+ struct skel_item_state *state;
};
#define PVT_BUCKETS 17
struct skel_config {
struct skel_global_config *general;
- struct ao2_container *cfgs;
+ struct ao2_container *items;
};
static void *skel_config_alloc(void);
-static void *skel_pvt_cfg_alloc(const char *cat);
-static int skel_cfg_exists(struct ao2_container *tmp_container, const char *category);
+static void *skel_item_alloc(const char *cat);
+static int skel_item_exists(struct ao2_container *tmp_container, const char *category);
static struct aco_type general_options = {
- .type = ACO_GLOBAL_OBJ,
- .cfg_offset = offsetof(struct skel_config, general),
- .category_allow = ACO_WHITELIST,
+ .type = ACO_GLOBAL,
+ .item_offset = offsetof(struct skel_config, general),
+ .category_match = ACO_WHITELIST,
.category = "general",
};
static struct aco_type private_options = {
- .type = ACO_PRIVATE_OBJ,
- .category_allow = ACO_BLACKLIST,
+ .type = ACO_ITEM,
+ .category_match = ACO_BLACKLIST,
.category = "general",
- .cfg_alloc = skel_pvt_cfg_alloc,
- .cfg_exists = skel_cfg_exists,
- .cfg_offset = offsetof(struct skel_config, cfgs),
+ .item_alloc = skel_item_alloc,
+ .item_exists = skel_item_exists,
+ .item_offset = offsetof(struct skel_config, items),
};
static AO2_GLOBAL_OBJ_STATIC(globals);
@@ -163,32 +163,32 @@
static void skel_global_config_destructor(void *obj)
{
- struct skel_global_config *cfg = obj;
- ast_string_field_free_memory(cfg);
-}
-
-static void skel_pvt_destructor(void *obj)
+ struct skel_global_config *global = obj;
+ ast_string_field_free_memory(global);
+}
+
+static void skel_state_destructor(void *obj)
{
return;
}
-static void skel_pvt_config_destructor(void *obj)
-{
- struct skel_pvt_config *cfg = obj;
- ast_string_field_free_memory(cfg);
- ao2_cleanup(cfg->pvt);
-}
-
-static int skel_pvt_config_hash(const void *obj, const int flags)
-{
- const struct skel_pvt_config *cfg = obj;
- const char *name = (flags & OBJ_KEY) ? obj : cfg->name;
+static void skel_item_destructor(void *obj)
+{
+ struct skel_item *item = obj;
+ ast_string_field_free_memory(item);
+ ao2_cleanup(item->state);
+}
+
+static int skel_item_hash(const void *obj, const int flags)
+{
+ const struct skel_item *item = obj;
+ const char *name = (flags & OBJ_KEY) ? obj : item->name;
return ast_str_case_hash(name);
}
-static int skel_pvt_config_cmp(void *obj, void *arg, int flags)
-{
- struct skel_pvt_config *one = obj, *two = arg;
+static int skel_item_cmp(void *obj, void *arg, int flags)
+{
+ struct skel_item *one = obj, *two = arg;
const char *match = (flags & OBJ_KEY) ? arg : two->name;
return strcasecmp(one->name, match) ? 0 : (CMP_MATCH | CMP_STOP);
}
@@ -199,12 +199,12 @@
*/
static int custom_bitfield_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
{
- struct skel_pvt_config *cfg = obj;
+ struct skel_item *item = obj;
if (!strcasecmp(var->name, "bit1")) {
- cfg->bit1 = ast_true(var->value);
+ item->bit1 = ast_true(var->value);
} else if (!strcasecmp(var->name, "bit2")) {
- cfg->bit2 = ast_true(var->value);
+ item->bit2 = ast_true(var->value);
} else {
return -1;
}
@@ -257,67 +257,67 @@
return res;
}
-static struct skel_pvt *skel_pvt_alloc(const char *name)
-{
- struct skel_pvt *pvt;
-
- if (!(pvt = ao2_alloc(sizeof(*pvt), skel_pvt_destructor))) {
- return NULL;
- }
-
- return pvt;
-}
-
-static int skel_cfg_exists(struct ao2_container *tmp_container, const char *category)
-{
- RAII_VAR(struct skel_pvt_config *, cfg, ao2_find(tmp_container, category, OBJ_KEY), ao2_cleanup);
- return cfg ? 1 : 0;
-}
-
-static void *skel_find_or_create_pvt(const char *category)
+static struct skel_item *skel_state_alloc(const char *name)
+{
+ struct skel_item *item;
+
+ if (!(item = ao2_alloc(sizeof(*item), skel_state_destructor))) {
+ return NULL;
+ }
+
+ return item;
+}
+
+static int skel_item_exists(struct ao2_container *tmp_container, const char *category)
+{
+ RAII_VAR(struct skel_item *, item, ao2_find(tmp_container, category, OBJ_KEY), ao2_cleanup);
+ return item ? 1 : 0;
+}
+
+static void *skel_find_or_create_state(const char *category)
{
RAII_VAR(struct skel_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
- RAII_VAR(struct skel_pvt_config *, obj, NULL, ao2_cleanup);
- if (!cfg || !cfg->cfgs || !(obj = ao2_find(cfg->cfgs, category, OBJ_KEY))) {
- return skel_pvt_alloc(category);
- }
- ao2_ref(obj->pvt, +1);
- return obj->pvt;
-}
-
-static void *skel_pvt_cfg_alloc(const char *cat)
-{
- struct skel_pvt_config *pvtcfg;
-
- if (!(pvtcfg = ao2_alloc(sizeof(*pvtcfg), skel_pvt_config_destructor))) {
- return NULL;
- }
-
- if (ast_string_field_init(pvtcfg, 128)) {
- ao2_ref(pvtcfg, -1);
- return NULL;
- }
-
- if (!(pvtcfg->caps = ast_format_cap_alloc_nolock())) {
- ao2_ref(pvtcfg, -1);
- return NULL;
- }
-
- if (!(pvtcfg->pvt = skel_find_or_create_pvt(cat))) {
- ao2_ref(pvtcfg, -1);
- return NULL;
- }
-
- ast_string_field_set(pvtcfg, name, cat);
-
- return pvtcfg;
+ RAII_VAR(struct skel_item *, item, NULL, ao2_cleanup);
+ if (!cfg || !cfg->items || !(item = ao2_find(cfg->items, category, OBJ_KEY))) {
+ return skel_state_alloc(category);
+ }
+ ao2_ref(item->state, +1);
+ return item->state;
+}
+
+static void *skel_item_alloc(const char *cat)
+{
+ struct skel_item *item;
+
+ if (!(item = ao2_alloc(sizeof(*item), skel_item_destructor))) {
+ return NULL;
+ }
+
+ if (ast_string_field_init(item, 128)) {
+ ao2_ref(item, -1);
+ return NULL;
+ }
+
+ if (!(item->caps = ast_format_cap_alloc_nolock())) {
+ ao2_ref(item, -1);
+ return NULL;
+ }
+
+ if (!(item->state = skel_find_or_create_state(cat))) {
+ ao2_ref(item, -1);
+ return NULL;
+ }
+
+ ast_string_field_set(item, name, cat);
+
+ return item;
}
static void skel_config_destructor(void *obj)
{
struct skel_config *cfg = obj;
ao2_cleanup(cfg->general);
- ao2_cleanup(cfg->cfgs);
+ ao2_cleanup(cfg->items);
}
static void *skel_config_alloc(void)
@@ -337,7 +337,7 @@
goto error;
}
- if (!(cfg->cfgs = ao2_container_alloc(PVT_BUCKETS, skel_pvt_config_hash, skel_pvt_config_cmp))) {
+ if (!(cfg->items = ao2_container_alloc(PVT_BUCKETS, skel_item_hash, skel_item_cmp))) {
goto error;
}
@@ -375,38 +375,38 @@
return CLI_SUCCESS;
}
-static char *handle_skel_show_pvts(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+static char *handle_skel_show_items(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
RAII_VAR(struct skel_config *, cfg, NULL, ao2_cleanup);
struct ao2_iterator iter;
- struct skel_pvt_config *pcfg;
+ struct skel_item *item;
char codec_buf[128];
switch(cmd) {
case CLI_INIT:
- e->command = "skel show privates";
+ e->command = "skel show items";
e->usage =
- "Usage: skel show privates\n"
- " List the app_skel privates\n";
+ "Usage: skel show items\n"
+ " List the app_skel items\n";
return NULL;
case CLI_GENERATE:
return NULL;
}
- if (!(cfg = ao2_global_obj_ref(globals)) || !cfg->cfgs) {
+ if (!(cfg = ao2_global_obj_ref(globals)) || !cfg->items) {
return NULL;
}
#define SKEL_FORMAT "%-15.15s %-25.25s %-20.20s %-5.5s %-5.5s %-5.5s %-2.2s\n"
#define SKEL_FORMAT1 "%-15.15s %-25.25s %-20.20s %-5.5s %-5.5s %-5.5s %-2.2zu\n"
ast_cli(a->fd, SKEL_FORMAT, "Name", "Description", "Codecs", "ACL", "Bit1", "Bit2", "N");
- iter = ao2_iterator_init(cfg->cfgs, 0);
- while ((pcfg = ao2_iterator_next(&iter))) {
+ iter = ao2_iterator_init(cfg->items, 0);
+ while ((item = ao2_iterator_next(&iter))) {
/* As an example of non-config-related state remaining between reloads */
- ++pcfg->pvt->non_config_state;
- ast_getformatname_multiple(codec_buf, sizeof(codec_buf) - 1, pcfg->caps);
- ast_cli(a->fd, SKEL_FORMAT1, pcfg->name, pcfg->description, codec_buf, AST_CLI_YESNO(pcfg->permit != NULL), AST_CLI_YESNO(pcfg->bit1), AST_CLI_YESNO(pcfg->bit2), pcfg->pvt->non_config_state);
- ao2_ref(pcfg, -1);
+ ++item->state->non_config_state;
+ ast_getformatname_multiple(codec_buf, sizeof(codec_buf) - 1, item->caps);
+ ast_cli(a->fd, SKEL_FORMAT1, item->name, item->description, codec_buf, AST_CLI_YESNO(item->permit != NULL), AST_CLI_YESNO(item->bit1), AST_CLI_YESNO(item->bit2), item->state->non_config_state);
+ ao2_ref(item, -1);
}
ao2_iterator_destroy(&iter);
#undef SKEL_FORMAT
@@ -417,7 +417,7 @@
static struct ast_cli_entry skel_cli[] = {
AST_CLI_DEFINE(handle_skel_show_config, "Show app_skel global config options"),
- AST_CLI_DEFINE(handle_skel_show_pvts, "Show app_skel private thingys"),
+ AST_CLI_DEFINE(handle_skel_show_items, "Show app_skel private thingys"),
};
static int reload_module(void)
@@ -451,9 +451,9 @@
aco_option_register(&cfg_info, "bindaddr", &general_options, "0.0.0.0:1234", OPT_SOCKADDR_T, PARSE_PORT_REQUIRE, FLDSET(struct skel_global_config, bindaddr));
/* Private Options */
- aco_option_register(&cfg_info, "description", &private_options, NULL, OPT_STRINGFIELD_T, 0, STRFLDSET(struct skel_pvt_config, description));
- aco_option_register(&cfg_info, "allow", &private_options, "ulaw,alaw", OPT_CODEC_T, 1, FLDSET(struct skel_pvt_config, prefs, caps));
- aco_option_register(&cfg_info, "permit", &private_options, NULL, OPT_ACL_T, 1, FLDSET(struct skel_pvt_config, permit));
+ aco_option_register(&cfg_info, "description", &private_options, NULL, OPT_STRINGFIELD_T, 0, STRFLDSET(struct skel_item, description));
+ aco_option_register(&cfg_info, "allow", &private_options, "ulaw,alaw", OPT_CODEC_T, 1, FLDSET(struct skel_item, prefs, caps));
+ aco_option_register(&cfg_info, "permit", &private_options, NULL, OPT_ACL_T, 1, FLDSET(struct skel_item, permit));
aco_option_register_custom(&cfg_info, "bit1", &private_options, "yes", custom_bitfield_handler, 0);
aco_option_register_custom(&cfg_info, "bit2", &private_options, "no", custom_bitfield_handler, 0);
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=366965&r1=366964&r2=366965
==============================================================================
--- team/twilson/config_work/include/asterisk/config_options.h (original)
+++ team/twilson/config_work/include/asterisk/config_options.h Fri May 18 11:12:53 2012
@@ -38,8 +38,8 @@
struct aco_info_internal;
enum aco_type_t {
- ACO_GLOBAL_OBJ,
- ACO_PRIVATE_OBJ,
+ ACO_GLOBAL,
+ ACO_ITEM,
};
/*! \brief Whether a category regex is a blackist or a whitelist */
@@ -55,15 +55,15 @@
* \retval NULL error
* \retval non-NULL a new configurable ao2 object
*/
-typedef void *(*aco_type_alloc)(const char *category);
-
-/*! \brief Find a private given a category and container of privates
- * \param container The container to search for the private
- * \param category The category associated with the private
+typedef void *(*aco_type_item_alloc)(const char *category);
+
+/*! \brief Find a item given a category and container of items
+ * \param container The container to search for the item
+ * \param category The category associated with the item
* \retval 1 config exists in container
* \retval 0 config does not exist in container
*/
-typedef int (*aco_type_cfg_exists)(struct ao2_container *newcontainer, const char *category);
+typedef int (*aco_type_item_exists)(struct ao2_container *newcontainer, const char *category);
/*! \brief Callback function that is called after a config object is initialized with defaults
*
@@ -72,11 +72,11 @@
* to merge in settings inherited from the global settings if necessary, despite that being a
* bad thing to do!
*
- * \param newcfg The newly allocated config object with defaults populated
+ * \param newitem The newly allocated config object with defaults populated
* \retval 0 succes, continue processing
* \retval non-zero failure, stop processing
*/
-typedef int (*aco_type_post_cfg_init)(void *newcfg);
+typedef int (*aco_type_post_item_init)(void *newitem);
/*! \brief Callback function that is called after config processing, but before linking
*
@@ -84,31 +84,30 @@
* in the config container. This callback can be used to verify that all settings make
* sense together, that required options have been set, etc.
*
- * \param newcfg The newly configured object
+ * \param newitem The newly configured object
* \retval 0 success, continue processing
* \retval non-zero failure, stop processing
*/
-typedef int (*aco_type_prelink)(void *newcfg);
+typedef int (*aco_type_prelink)(void *newitem);
/*! \struct aco_type
* \brief Type information about a category-level configurable object
*/
struct aco_type {
/* common stuff */
- enum aco_type_t type; /*!< Whether this is a global or private type */
+ enum aco_type_t type; /*!< Whether this is a global or item type */
const char *category; /*!< A regular expression for matching categories to be allowed or denied */
const char *matchfield; /*!< An option name to match for this type (i.e. a 'type'-like column) */
const char *matchvalue; /*!< The value of the option to require for matching (i.e. 'peer' for type= in sip.conf) */
regex_t *regex;
- enum aco_category_op category_allow; /*!< Whether the following category regex is a whitelist or blacklist */
- size_t cfg_offset; /*!< The offset in the config snapshot for the global config or private config container */
- size_t pvt_offset; /*!< The offset in the config snapshot for the private container */
- aco_type_alloc cfg_alloc; /*!< An allocation function for ao2 object associated with this type */
+ enum aco_category_op category_match; /*!< Whether the following category regex is a whitelist or blacklist */
+ size_t item_offset; /*!< The offset in the config snapshot for the global config or item config container */
/* non-global callbacks */
- aco_type_cfg_exists cfg_exists; /*!< A callback function to find an existing private in a particular container */
- aco_type_post_cfg_init post_cfg_init; /*!< An optional callback function that is called after defaults are applied, but before config processing */
- aco_type_prelink prelink; /*!< An optional callback function that is called after config processing, but before applying changes */
+ aco_type_item_alloc item_alloc; /*!< An allocation function for item associated with this type */
+ aco_type_item_exists item_exists; /*!< A callback function to find an existing item in a particular container */
+ aco_type_post_item_init item_post_init; /*!< An optional callback function that is called after defaults are applied, but before config processing */
+ aco_type_prelink item_prelink; /*!< An optional callback function that is called after config processing, but before applying changes */
};
/*! \brief A callback function for applying the config changes
@@ -127,7 +126,7 @@
const char *module; /*!< The name of the module whose config is being processed */
const char *filename; /*!< The config filename */
aco_pre_apply_config pre_apply_config; /*!< A callback called after processing, but before changes are applied */
- aco_snapshot_alloc snapshot_alloc; /*!< Allocate an object to hold all global configs and private containers */
+ aco_snapshot_alloc snapshot_alloc; /*!< Allocate an object to hold all global configs and item containers */
struct ao2_global_obj *global_obj; /*!< The global object array that holds the user-defined config object */
const char **preload; /*!< Categories to parse first. Do something like char *arr[] = {"general", NULL}; and do .preload = arr */
struct aco_info_internal *internal;
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=366965&r1=366964&r2=366965
==============================================================================
--- team/twilson/config_work/main/config_options.c (original)
+++ team/twilson/config_work/main/config_options.c Fri May 18 11:12:53 2012
@@ -52,7 +52,7 @@
const char *default_val;
struct aco_type *obj;
enum aco_option_type type;
- enum aco_category_op category_allow;
+ enum aco_category_op category_match;
aco_option_handler handler;
unsigned int flags;
size_t argc;
@@ -73,26 +73,26 @@
return;
}
-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 int int_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
+static int uint_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
+static int double_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
+static int sockaddr_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
+static int stringfield_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
+static int bool_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
+static int acl_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
+static int codec_handler_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;
- case OPT_BOOL_T: return ast_config_option_bool_fn;
- case OPT_CODEC_T: return ast_config_option_codec_fn;
- case OPT_DOUBLE_T: return ast_config_option_double_fn;
- case OPT_INT_T: return ast_config_option_int_fn;
- case OPT_SOCKADDR_T: return ast_config_option_sockaddr_fn;
- case OPT_STRINGFIELD_T: return ast_config_option_stringfield_fn;
- case OPT_UINT_T: return ast_config_option_uint_fn;
+ case OPT_ACL_T: return acl_handler_fn;
+ case OPT_BOOL_T: return bool_handler_fn;
+ case OPT_CODEC_T: return codec_handler_fn;
+ case OPT_DOUBLE_T: return double_handler_fn;
+ case OPT_INT_T: return int_handler_fn;
+ case OPT_SOCKADDR_T: return sockaddr_handler_fn;
+ case OPT_STRINGFIELD_T: return stringfield_handler_fn;
+ case OPT_UINT_T: return uint_handler_fn;
case OPT_CUSTOM_T: return NULL;
}
@@ -189,7 +189,7 @@
const char *name = arg, *category = data;
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, category, 0, NULL, 0) == !match->obj->category_allow ? 0 : CMP_MATCH | CMP_STOP;
+ return strcasecmp(name, match->name) || !regexec(match->obj->regex, category, 0, NULL, 0) == !match->obj->category_match ? 0 : CMP_MATCH | CMP_STOP;
}
struct aco_option *aco_option_find(struct ao2_container *container, const char *name, const char *cat)
@@ -210,7 +210,7 @@
for (x = 0, match = info->types[x]; match; match = info->types[++x]) {
/* First make sure we are an object that can service this category */
- if (!regexec(match->regex, category, 0, NULL, 0) == !match->category_allow) {
+ if (!regexec(match->regex, category, 0, NULL, 0) == !match->category_match) {
continue;
}
@@ -248,24 +248,31 @@
}
static int process_category(struct ast_config *cfg, struct aco_info *info, const char *cat, int preload) {
- RAII_VAR(void *, tmpcfg, NULL, ao2_cleanup);
+ RAII_VAR(void *, new_item, NULL, ao2_cleanup);
struct aco_type *obj;
+ /* For global types, field is the global option struct. For non-global, it is the container for items.
+ * We do not grab a reference to these objects, as the info already holds references to them. This
+ * pointer is just a convenience. Do not actually store it somewhere. */
+ void **field;
/* Skip preloaded categories if we aren't preloading */
if (!preload && is_preload(info, cat)) {
return 0;
}
- /* Find config object by category, if not found it is an error */
+ /* Find aco_type by category, if not found it is an error */
if (!(obj = internal_aco_type_find(info, cfg, cat))) {
ast_log(LOG_ERROR, "Could not find config type for category '%s' in '%s'\n", cat, info->filename);
return -1;
}
- /* if type == GLOBAL_OBJ, set defaults and configure the cached cfg object */
- if (obj->type == ACO_GLOBAL_OBJ && info->internal->pending + obj->cfg_offset) {
- void **field = info->internal->pending + obj->cfg_offset;
-
+ field = info->internal->pending + obj->item_offset;
+ if (!*field) {
+ ast_log(LOG_ERROR, "No object to update!\n");
+ return -1;
+ }
+
+ if (obj->type == ACO_GLOBAL && *field) {
if (aco_set_defaults(info->internal->opts, cat, *field)) {
ast_log(LOG_ERROR, "In %s: Setting defaults for %s failed\n", info->filename, cat);
return -1;
@@ -274,44 +281,41 @@
ast_log(LOG_ERROR, "In %s: Processing options for %s failed\n", info->filename, cat);
return -1;
}
- } else if (obj->type == ACO_PRIVATE_OBJ) {
- void **field = info->internal->pending + obj->cfg_offset;
- /* If we've already linked a private for cat in newpvts, don't add a second one with the same name */
+ } else if (obj->type == ACO_ITEM) {
+ /* If we've already linked an item for this category, don't add a second one with the same name */
if (*field) {
- if ((obj->cfg_exists(*field, cat))) {
+ if ((obj->item_exists(*field, cat))) {
ast_log(LOG_ERROR, "In %s: Multiple definitions of %s!\n", info->filename, cat);
return -1;
}
}
- /* allocates a private if necessary */
- if (!(tmpcfg = obj->cfg_alloc(cat))) {
- ast_log(LOG_ERROR, "In %s: Could not create private config object for %s\n", info->filename, cat);
- return -1;
- }
-
- if (aco_set_defaults(info->internal->opts, cat, tmpcfg)) {
+ if (!(new_item = obj->item_alloc(cat))) {
+ ast_log(LOG_ERROR, "In %s: Could not create item for %s\n", info->filename, cat);
+ return -1;
+ }
+
+ if (aco_set_defaults(info->internal->opts, cat, new_item)) {
ast_log(LOG_ERROR, "In %s: Setting defaults for %s failed\n", info->filename, cat);
return -1;
}
- if (obj->post_cfg_init && obj->post_cfg_init(tmpcfg)) {
+ if (obj->item_post_init && obj->item_post_init(new_item)) {
ast_log(LOG_ERROR, "In %s: Post-init callback for %s failed\n", info->filename, cat);
return -1;
}
- if (aco_process_category_options(info->internal->opts, cfg, cat, tmpcfg)) {
+ if (aco_process_category_options(info->internal->opts, cfg, cat, new_item)) {
ast_log(LOG_ERROR, "In %s: Processing options for %s failed\n", info->filename, cat);
return -1;
}
- if (obj->prelink && obj->prelink(tmpcfg)) {
+ if (obj->item_prelink && obj->item_prelink(new_item)) {
ast_log(LOG_ERROR, "In %s: Pre-link callback for %s failed\n", info->filename, cat);
return -1;
}
- /* We have a valid pvt/cfg, link 'em */
- if (!ao2_link(*field, tmpcfg)) {
+ if (!ao2_link(*field, new_item)) {
ast_log(LOG_ERROR, "In %s: Linking config for %s failed\n", info->filename, cat);
return -1;
}
@@ -481,7 +485,7 @@
internal_info_types_destroy(info);
}
-/*! \brief match for anything where the category passes (or fails if !category_allow) the category regex
+/*! \brief match for anything where the category passes (or fails if !category_match) the category regex
* \internal
*/
static int match_option_by_category(void *obj, void *arg, int flags)
@@ -489,7 +493,7 @@
struct aco_option *match = obj;
const char *category = arg;
- return !regexec(match->obj->regex, category, 0, NULL, 0) == !match->obj->category_allow ? 0 : CMP_MATCH;
+ return !regexec(match->obj->regex, category, 0, NULL, 0) == !match->obj->category_match ? 0 : CMP_MATCH;
}
int aco_set_defaults(struct ao2_container *container, const char *category, void *obj)
@@ -524,7 +528,7 @@
}
/* default config option handlers */
-int ast_config_option_int_fn(const struct aco_option *opt, struct ast_variable *var, void *obj) {
+static int int_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj) {
int *field = (int *)(obj + opt->args[0]);
unsigned int flags = PARSE_INT32 | opt->flags;
int res = 0;
@@ -550,7 +554,7 @@
return res;
}
-int ast_config_option_uint_fn(const struct aco_option *opt, struct ast_variable *var, void *obj) {
+static int uint_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj) {
unsigned int *field = (unsigned int *)(obj + opt->args[0]);
unsigned int flags = PARSE_INT32 | opt->flags;
int res = 0;
@@ -576,12 +580,12 @@
return res;
}
-int ast_config_option_double_fn(const struct aco_option *opt, struct ast_variable *var, void *obj) {
+static int double_handler_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 aco_option *opt, struct ast_variable *var, void *obj) {
+static int acl_handler_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);
@@ -589,14 +593,14 @@
}
/* opt->args[0] = struct ast_codec_pref, opt->args[1] struct ast_format_cap * */
-int ast_config_option_codec_fn(const struct aco_option *opt, struct ast_variable *var, void *obj) {
+static int codec_handler_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_mgr */
-int ast_config_option_stringfield_fn(const struct aco_option *opt, struct ast_variable *var, void *obj)
+static int stringfield_handler_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]);
@@ -605,14 +609,14 @@
return 0;
}
-int ast_config_option_bool_fn(const struct aco_option *opt, struct ast_variable *var, void *obj)
+static int bool_handler_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 aco_option *opt, struct ast_variable *var, void *obj)
+static int sockaddr_handler_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);
Modified: team/twilson/config_work/main/udptl.c
URL: http://svnview.digium.com/svn/asterisk/team/twilson/config_work/main/udptl.c?view=diff&rev=366965&r1=366964&r2=366965
==============================================================================
--- team/twilson/config_work/main/udptl.c (original)
+++ team/twilson/config_work/main/udptl.c Fri May 18 11:12:53 2012
@@ -193,8 +193,8 @@
static int udptl_pre_apply_config(void);
static struct aco_type general_options = {
- .type = ACO_GLOBAL_OBJ,
- .category_allow = ACO_WHITELIST,
+ .type = ACO_GLOBAL,
+ .category_match = ACO_WHITELIST,
.category = "general",
};
More information about the asterisk-commits
mailing list