]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
sorcery: Add ast_sorcery_object_unregister() API call. 87/687/3
authorRichard Mudgett <rmudgett@digium.com>
Mon, 15 Jun 2015 20:28:00 +0000 (15:28 -0500)
committerRichard Mudgett <rmudgett@digium.com>
Thu, 25 Jun 2015 16:33:41 +0000 (11:33 -0500)
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

include/asterisk/sorcery.h
main/sorcery.c

index 92d6f6cb7fad51df8f91a7154f8829e422ab3bcc..30fb0dd02a0f6ce1f84219e5b8b5be3d3aec6080 100644 (file)
@@ -616,6 +616,17 @@ int ast_sorcery_get_wizard_mapping_count(struct ast_sorcery *sorcery,
 int ast_sorcery_get_wizard_mapping(struct ast_sorcery *sorcery,
        const char *type, int index, struct ast_sorcery_wizard **wizard, void **data);
 
+/*!
+ * \brief Unregister an object type
+ *
+ * \param sorcery Pointer to a sorcery structure
+ * \param type Type of object
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ */
+int ast_sorcery_object_unregister(struct ast_sorcery *sorcery, const char *type);
+
 /*!
  * \brief Register an object type
  *
index 8101af055e3e59f4da279c4fc8c2fe8a44bbe2d8..063e8c4b03298e318421598e77bceb20b8f6390c 100644 (file)
@@ -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);