diff options
author | Richard Mudgett <rmudgett@digium.com> | 2015-06-15 15:28:00 -0500 |
---|---|---|
committer | Richard Mudgett <rmudgett@digium.com> | 2015-06-25 14:30:48 -0500 |
commit | 9ec8a0f3ccdb0e308ed480aff3ad1e1c9a82f674 (patch) | |
tree | ac88bad1b55277a92b76b40ff80efcccfb1d39fc /main/sorcery.c | |
parent | 77ff7325a221160f0aef856a282ae6de6f5d8088 (diff) |
sorcery: Add ast_sorcery_object_unregister() API call.
Find and unlink the specified sorcery object type to complement
ast_sorcery_object_register(). Without this function you cannot
completely unload individual modules that use sorcery for configuration.
ASTERISK-24907
Reported by: Kevin Harwell
Change-Id: I1c04634fe9a90921bf676725c7d6bb2aeaab1c88
Diffstat (limited to 'main/sorcery.c')
-rw-r--r-- | main/sorcery.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/main/sorcery.c b/main/sorcery.c index f84855eff..1ff83de66 100644 --- a/main/sorcery.c +++ b/main/sorcery.c @@ -1106,6 +1106,25 @@ static int sorcery_extended_fields_handler(const void *obj, struct ast_variable return 0; } +int ast_sorcery_object_unregister(struct ast_sorcery *sorcery, const char *type) +{ + struct ast_sorcery_object_type *object_type; + int res = -1; + + ao2_wrlock(sorcery->types); + object_type = ao2_find(sorcery->types, type, OBJ_SEARCH_KEY | OBJ_NOLOCK); + if (object_type && object_type->type.type == ACO_ITEM) { + ao2_unlink_flags(sorcery->types, object_type, OBJ_NOLOCK); + res = 0; + } + ao2_unlock(sorcery->types); + + /* XXX may need to add an instance unregister observer callback on success. */ + + ao2_cleanup(object_type); + return res; +} + int __ast_sorcery_object_register(struct ast_sorcery *sorcery, const char *type, unsigned int hidden, unsigned int reloadable, aco_type_item_alloc alloc, sorcery_transform_handler transform, sorcery_apply_handler apply) { RAII_VAR(struct ast_sorcery_object_type *, object_type, ao2_find(sorcery->types, type, OBJ_KEY), ao2_cleanup); |