summaryrefslogtreecommitdiff
path: root/res/ari
diff options
context:
space:
mode:
authorRichard Mudgett <rmudgett@digium.com>2015-09-25 17:26:08 -0500
committerRichard Mudgett <rmudgett@digium.com>2015-09-29 12:10:45 -0500
commit3f4fa245e5ccc0e0e583a50253f23444012ca879 (patch)
tree6a75016fc83d4d8a279d079b00065a98f6d539f3 /res/ari
parentaa00df62ee8706db4a64b3591f15e2e19a136d09 (diff)
res/ari/config.c: Optimize conf_alloc() object init.
* Now conf_alloc() has more off nominal error checking. * Eliminated RAII_VAR() use in conf_alloc(). * Eliminated a dubius shortcut when destroying cfg->general in conf_destructor() that would cause a crash if cfg->general failed to get allocated. * Add some ACO registration section comments. Change-Id: Ia40c2b1b2d0777d641605118ae019c5a73865e1a
Diffstat (limited to 'res/ari')
-rw-r--r--res/ari/config.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/res/ari/config.c b/res/ari/config.c
index 6d2a67954..ba06fe9c9 100644
--- a/res/ari/config.c
+++ b/res/ari/config.c
@@ -155,13 +155,18 @@ static struct aco_type user_option = {
static struct aco_type *user[] = ACO_TYPES(&user_option);
+static void conf_general_dtor(void *obj)
+{
+ struct ast_ari_conf_general *general = obj;
+
+ ast_string_field_free_memory(general);
+}
+
/*! \brief \ref ast_ari_conf destructor. */
static void conf_destructor(void *obj)
{
struct ast_ari_conf *cfg = obj;
- ast_string_field_free_memory(cfg->general);
-
ao2_cleanup(cfg->general);
ao2_cleanup(cfg->users);
}
@@ -169,7 +174,7 @@ static void conf_destructor(void *obj)
/*! \brief Allocate an \ref ast_ari_conf for config parsing */
static void *conf_alloc(void)
{
- RAII_VAR(struct ast_ari_conf *, cfg, NULL, ao2_cleanup);
+ struct ast_ari_conf *cfg;
cfg = ao2_alloc_options(sizeof(*cfg), conf_destructor,
AO2_ALLOC_OPT_LOCK_NOLOCK);
@@ -177,20 +182,20 @@ static void *conf_alloc(void)
return NULL;
}
- cfg->general = ao2_alloc_options(sizeof(*cfg->general), NULL,
+ cfg->general = ao2_alloc_options(sizeof(*cfg->general), conf_general_dtor,
AO2_ALLOC_OPT_LOCK_NOLOCK);
- if (!cfg->general) {
- return NULL;
- }
- if (ast_string_field_init(cfg->general, 64)) {
- return NULL;
- }
- aco_set_defaults(&general_option, "general", cfg->general);
cfg->users = ao2_container_alloc_rbtree(AO2_ALLOC_OPT_LOCK_NOLOCK,
AO2_CONTAINER_ALLOC_OPT_DUPS_REPLACE, user_sort_cmp, NULL);
- ao2_ref(cfg, +1);
+ if (!cfg->users
+ || !cfg->general
+ || ast_string_field_init(cfg->general, 64)
+ || aco_set_defaults(&general_option, "general", cfg->general)) {
+ ao2_ref(cfg, -1);
+ return NULL;
+ }
+
return cfg;
}
@@ -308,6 +313,7 @@ int ast_ari_config_init(void)
return -1;
}
+ /* ARI general category options */
aco_option_register(&cfg_info, "enabled", ACO_EXACT, general_options,
"yes", OPT_BOOL_T, 1,
FLDSET(struct ast_ari_conf_general, enabled));
@@ -324,6 +330,7 @@ int ast_ari_config_init(void)
AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT_STR, OPT_INT_T, PARSE_IN_RANGE,
FLDSET(struct ast_ari_conf_general, write_timeout), 1, INT_MAX);
+ /* ARI type=user category options */
aco_option_register(&cfg_info, "type", ACO_EXACT, user, NULL,
OPT_NOOP_T, 0, 0);
aco_option_register(&cfg_info, "read_only", ACO_EXACT, user,