2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2012 - 2013, Digium, Inc.
6 * Joshua Colp <jcolp@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
20 * \brief Sorcery Data Access Layer API
21 * \author Joshua Colp <jcolp@digium.com>
26 * \page AstSorcery Data Access Layer API
28 * Sorcery is a unifying data access layer which utilizes the configuration framework,
29 * realtime, and astdb to allow object creation, retrieval, updating, and deletion.
33 * Usage of sorcery is accomplished by first opening a sorcery structure. This structure holds
34 * all information about the object types, object fields, and object mappings. All API functions
35 * require the sorcery structure to operate. When sorcery is no longer needed the structure can
36 * be unreferenced using \ref ast_sorcery_unref
38 * Once opened the sorcery structure must have object mappings applied to it. This maps the
39 * object types to their respective wizards (object storage modules). If the developer would like
40 * to allow the user to configure this using the sorcery.conf configuration file the
41 * \ref ast_sorcery_apply_config API call can be used to read in the configuration file and apply the
42 * mappings. If the storage of the object types are such that a default wizard can be used this can
43 * be applied using the \ref ast_sorcery_apply_default API call. Note that the default mappings will not
44 * override configured mappings. They are only used in the case where no configured mapping exists.
46 * Configuring object mappings implicitly creates a basic version of an object type. The object type
47 * must be fully registered, however, using the \ref ast_sorcery_object_register API call before any
48 * objects of the type can be allocated, created, or retrieved.
50 * Once the object type itself has been fully registered the individual fields within the object must
51 * be registered using the \ref ast_sorcery_object_field_register API call. Note that not all fields *need*
52 * be registered. Only fields that should be accessible using the sorcery API have to be registered.
54 * \par Creating Objects
56 * Before an object can be created within the sorcery API it must first be allocated using the
57 * \ref ast_sorcery_alloc API call. This allocates a new instance of the object, sets sorcery specific
58 * details, and applies default values to the object. A unique identifier can optionally be specified
59 * when allocating an object. If it is not provided one will be automatically generated. Allocating
60 * an object does not create it within any object storage mechanisms that are configured for the
61 * object type. Creation must explicitly be done using the \ref ast_sorcery_create API call. This API call
62 * passes the object to each configured object storage mechanism for the object type until one
63 * successfully persists the object.
65 * \par Retrieving Objects
67 * To retrieve a single object using its unique identifier the \ref ast_sorcery_retrieve_by_id API call
70 * To retrieve potentially multiple objects using specific fields the \ref ast_sorcery_retrieve_by_fields
71 * API call can be used. The behavior of this API call is controlled using different flags. If the
72 * AST_RETRIEVE_FLAG_MULTIPLE flag is used a container will be returned which contains all matching objects.
73 * To retrieve all objects the AST_RETRIEVE_FLAG_ALL flag can be specified. Note that when specifying this flag
74 * you do not need to pass any fields.
76 * Both API calls return shared objects. Modification of the object can not occur until it has been copied.
78 * \par Updating Objects
80 * As retrieved objects may be shared the first step to updating the object with new details is creating a
81 * copy using the \ref ast_sorcery_copy API call. This will return a new object which is specific to the caller.
82 * Any field within the object may be modified as needed. Once changes are done the changes can be committed
83 * using the \ref ast_sorcery_update API call. Note that as the copied object is specific to the caller it must
84 * be unreferenced after use.
86 * \par Deleting Objects
88 * To delete an object simply call the \ref ast_sorcery_delete API call with an object retrieved using the
89 * ast_sorcery_retrieve_by_* API calls or a copy returned from \ref ast_sorcery_copy.
92 #ifndef _ASTERISK_SORCERY_H
93 #define _ASTERISK_SORCERY_H
95 #if defined(__cplusplus) || defined(c_plusplus)
99 #include "asterisk/config_options.h"
100 #include "asterisk/uuid.h"
102 /*! \brief Maximum size of an object type */
103 #define MAX_OBJECT_TYPE 64
105 /*! \brief Maximum length of an object field name */
106 #define MAX_OBJECT_FIELD 128
109 * \brief Retrieval flags
111 enum ast_sorcery_retrieve_flags {
112 /*! \brief Default retrieval flags */
113 AST_RETRIEVE_FLAG_DEFAULT = 0,
115 /*! \brief Return all matching objects */
116 AST_RETRIEVE_FLAG_MULTIPLE = (1 << 0),
118 /*! \brief Perform no matching, return all objects */
119 AST_RETRIEVE_FLAG_ALL = (1 << 1),
123 * \brief Field handler flags
125 enum ast_sorcery_field_handler_flags {
126 /*! \brief Try both handlers, string first */
127 AST_HANDLER_PREFER_STRING,
129 /*! \brief Try both handlers, list first */
130 AST_HANDLER_PREFER_LIST,
132 /*! \brief Use string handler only */
133 AST_HANDLER_ONLY_STRING,
135 /*! \brief Use list handler only */
136 AST_HANDLER_ONLY_LIST,
140 /*! \brief Forward declaration for the sorcery main structure */
144 * \brief A callback function for translating a value into a string
146 * \param obj Object to get value from
147 * \param args Where the field is
148 * \param buf Pointer to the buffer that the handler has created which contains the field value
153 typedef int (*sorcery_field_handler)(const void *obj, const intptr_t *args, char **buf);
156 * \brief A callback function for translating multiple values into an ast_variable list
158 * \param obj Object to get values from
159 * \param fields Pointer to store the list of fields
164 typedef int (*sorcery_fields_handler)(const void *obj, struct ast_variable **fields);
167 * \brief A callback function for performing a transformation on an object set
169 * \param set The existing object set
171 * \retval non-NULL new object set if changed
172 * \retval NULL if no changes present
174 * \note The returned ast_variable list must be *new*. You can not return the input set.
176 typedef struct ast_variable *(*sorcery_transform_handler)(struct ast_variable *set);
179 * \brief A callback function for when an object set is successfully applied to an object
181 * \note On a failure return, the state of the object is left undefined. It is a bad
182 * idea to try to use this object.
184 * \param sorcery Sorcery structure in use
185 * \param obj The object itself
187 * \retval non-zero Failure
189 typedef int (*sorcery_apply_handler)(const struct ast_sorcery *sorcery, void *obj);
192 * \brief A callback function for copying the contents of one object to another
194 * \param src The source object
195 * \param dst The destination object
200 typedef int (*sorcery_copy_handler)(const void *src, void *dst);
203 * \brief A callback function for generating a changeset between two objects
205 * \param original The original object
206 * \param modified The modified object
207 * \param changes The changeset
212 typedef int (*sorcery_diff_handler)(const void *original, const void *modified, struct ast_variable **changes);
214 /*! \brief Interface for a sorcery wizard */
215 struct ast_sorcery_wizard {
216 /*! \brief Name of the wizard */
219 /*! \brief Pointer to the Asterisk module this wizard is implemented by */
220 struct ast_module *module;
222 /*! \brief Callback for opening a wizard */
223 void *(*open)(const char *data);
225 /*! \brief Optional callback for loading persistent objects */
226 void (*load)(void *data, const struct ast_sorcery *sorcery, const char *type);
228 /*! \brief Optional callback for reloading persistent objects */
229 void (*reload)(void *data, const struct ast_sorcery *sorcery, const char *type);
231 /*! \brief Callback for creating an object */
232 int (*create)(const struct ast_sorcery *sorcery, void *data, void *object);
234 /*! \brief Callback for retrieving an object using an id */
235 void *(*retrieve_id)(const struct ast_sorcery *sorcery, void *data, const char *type, const char *id);
237 /*! \brief Callback for retrieving multiple objects using a regex on their id */
238 void (*retrieve_regex)(const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects, const char *regex);
240 /*! \brief Optional callback for retrieving an object using fields */
241 void *(*retrieve_fields)(const struct ast_sorcery *sorcery, void *data, const char *type, const struct ast_variable *fields);
243 /*! \brief Optional callback for retrieving multiple objects using some optional field criteria */
244 void (*retrieve_multiple)(const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects, const struct ast_variable *fields);
246 /*! \brief Callback for updating an object */
247 int (*update)(const struct ast_sorcery *sorcery, void *data, void *object);
249 /*! \brief Callback for deleting an object */
250 int (*delete)(const struct ast_sorcery *sorcery, void *data, void *object);
252 /*! \brief Callback for closing a wizard */
253 void (*close)(void *data);
256 /*! \brief Interface for a sorcery object type observer */
257 struct ast_sorcery_observer {
258 /*! \brief Callback for when an object is created */
259 void (*created)(const void *object);
261 /*! \brief Callback for when an object is updated */
262 void (*updated)(const void *object);
264 /*! \brief Callback for when an object is deleted */
265 void (*deleted)(const void *object);
267 /*! \brief Callback for when an object type is loaded/reloaded */
268 void (*loaded)(const char *object_type);
271 /*! \brief Opaque structure for internal sorcery object */
272 struct ast_sorcery_object;
274 /*! \brief Structure which contains details about a sorcery object */
275 struct ast_sorcery_object_details {
276 /*! \brief Pointer to internal sorcery object information */
277 struct ast_sorcery_object *object;
280 /*! \brief Macro which must be used at the beginning of each sorcery capable object */
281 #define SORCERY_OBJECT(details) \
283 struct ast_sorcery_object_details details; \
287 * \brief Initialize the sorcery API
292 int ast_sorcery_init(void);
295 * \brief Register a sorcery wizard
297 * \param interface Pointer to a wizard interface
298 * \param module Pointer to the module implementing the interface
303 int __ast_sorcery_wizard_register(const struct ast_sorcery_wizard *interface, struct ast_module *module);
306 * \brief See \ref __ast_sorcery_wizard_register()
308 #define ast_sorcery_wizard_register(interface) __ast_sorcery_wizard_register(interface, ast_module_info ? ast_module_info->self : NULL)
311 * \brief Unregister a sorcery wizard
313 * \param interface Pointer to the wizard interface
318 int ast_sorcery_wizard_unregister(const struct ast_sorcery_wizard *interface);
321 * \brief Open a new sorcery structure
323 * \param module The module name (AST_MODULE)
325 * \retval non-NULL success
326 * \retval NULL if allocation failed
328 struct ast_sorcery *__ast_sorcery_open(const char *module);
330 #define ast_sorcery_open() __ast_sorcery_open(AST_MODULE)
333 * \brief Retrieves an existing sorcery instance by module name
335 * \param module The module name
337 * \retval non-NULL success
338 * \retval NULL if no instance was found
340 * \note The returned instance has its reference count incremented. The caller
341 * must decrement the count when they're finished with it.
344 struct ast_sorcery *ast_sorcery_retrieve_by_module_name(const char *module);
347 * \brief Apply configured wizard mappings
349 * \param sorcery Pointer to a sorcery structure
350 * \param name Name of the category to use within the configuration file, normally the module name
351 * \param module The module name (AST_MODULE)
356 int __ast_sorcery_apply_config(struct ast_sorcery *sorcery, const char *name, const char *module);
358 #define ast_sorcery_apply_config(sorcery, name) \
359 __ast_sorcery_apply_config((sorcery), (name), AST_MODULE)
362 * \brief Apply default object wizard mappings
364 * \param sorcery Pointer to a sorcery structure
365 * \param type Type of object to apply to
366 * \param module The name of the module, typically AST_MODULE
367 * \param name Name of the wizard to use
368 * \param data Data to be passed to wizard
373 * \note This should be called *after* applying configuration sourced mappings
375 * \note Only a single default can exist per object type
377 int __ast_sorcery_apply_default(struct ast_sorcery *sorcery, const char *type, const char *module, const char *name, const char *data);
379 #define ast_sorcery_apply_default(sorcery, type, name, data) \
380 __ast_sorcery_apply_default((sorcery), (type), AST_MODULE, (name), (data))
383 * \brief Register an object type
385 * \param sorcery Pointer to a sorcery structure
386 * \param type Type of object
387 * \param hidden All objects of this type are internal and should not be manipulated by users
388 * \param reloadable All objects of this type are reloadable
389 * \param alloc Required object allocation callback
390 * \param transform Optional transformation callback
391 * \param apply Optional object set apply callback
393 * \note In general, this function should not be used directly. One of the various
394 * macro'd versions should be used instead.
399 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);
402 * \brief Register an object type
404 * \param sorcery Pointer to a sorcery structure
405 * \param type Type of object
406 * \param alloc Required object allocation callback
407 * \param transform Optional transformation callback
408 * \param apply Optional object set apply callback
413 #define ast_sorcery_object_register(sorcery, type, alloc, transform, apply) \
414 __ast_sorcery_object_register((sorcery), (type), 0, 1, (alloc), (transform), (apply))
417 * \brief Register an object type that is not reloadable
419 * \param sorcery Pointer to a sorcery structure
420 * \param type Type of object
421 * \param alloc Required object allocation callback
422 * \param transform Optional transformation callback
423 * \param apply Optional object set apply callback
428 #define ast_sorcery_object_register_no_reload(sorcery, type, alloc, transform, apply) \
429 __ast_sorcery_object_register((sorcery), (type), 0, 0, (alloc), (transform), (apply))
432 * \brief Register an internal, hidden object type
434 * \param sorcery Pointer to a sorcery structure
435 * \param type Type of object
436 * \param alloc Required object allocation callback
437 * \param transform Optional transformation callback
438 * \param apply Optional object set apply callback
443 #define ast_sorcery_internal_object_register(sorcery, type, alloc, transform, apply) \
444 __ast_sorcery_object_register((sorcery), (type), 1, 1, (alloc), (transform), (apply))
447 * \brief Set the copy handler for an object type
449 * \param sorcery Pointer to a sorcery structure
450 * \param type Type of object
451 * \param copy Copy handler
453 void ast_sorcery_object_set_copy_handler(struct ast_sorcery *sorcery, const char *type, sorcery_copy_handler copy);
456 * \brief Set the diff handler for an object type
458 * \param sorcery Pointer to a sorcery structure
459 * \param type Type of object
460 * \param diff Diff handler
462 void ast_sorcery_object_set_diff_handler(struct ast_sorcery *sorcery, const char *type, sorcery_diff_handler diff);
465 * \brief Register a regex for multiple fields within an object
467 * \param sorcery Pointer to a sorcery structure
468 * \param type Type of object
469 * \param regex A regular expression pattern for the fields
470 * \param config_handler A custom handler for translating the string representation of the fields
471 * \param sorcery_handler A custom handler for translating the native representation of the fields
476 int ast_sorcery_object_fields_register(struct ast_sorcery *sorcery, const char *type, const char *regex, aco_option_handler config_handler,
477 sorcery_fields_handler sorcery_handler);
480 * \brief Register a field within an object
482 * \param sorcery Pointer to a sorcery structure
483 * \param type Type of object
484 * \param name Name of the field
485 * \param default_val Default value of the field
486 * \param config_handler A custom handler for translating the string representation of the fields
487 * \param sorcery_handler A custom handler for translating the native representation of the fields
488 * \param multiple_handler A custom handler for translating the native representation of the fields
489 * \param opt_type Option type
490 * \param flags Option type specific flags
495 int __ast_sorcery_object_field_register(struct ast_sorcery *sorcery, const char *type,
496 const char *name, const char *default_val, enum aco_option_type opt_type,
497 aco_option_handler config_handler, sorcery_field_handler sorcery_handler,
498 sorcery_fields_handler multiple_handler, unsigned int flags, unsigned int no_doc, size_t argc, ...);
501 * \brief Register a field within an object
503 * \param sorcery Pointer to a sorcery structure
504 * \param type Type of object
505 * \param name Name of the field
506 * \param default_val Default value of the field
507 * \param opt_type Option type
508 * \param flags Option type specific flags
513 #define ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags, ...) \
514 __ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, NULL, NULL, NULL, flags, 0, VA_NARGS(__VA_ARGS__), __VA_ARGS__)
517 * \brief Register a field within an object without documentation
519 * \param sorcery Pointer to a sorcery structure
520 * \param type Type of object
521 * \param name Name of the field
522 * \param default_val Default value of the field
523 * \param opt_type Option type
524 * \param flags Option type specific flags
529 #define ast_sorcery_object_field_register_nodoc(sorcery, type, name, default_val, opt_type, flags, ...) \
530 __ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, NULL, NULL, NULL, flags, 1, VA_NARGS(__VA_ARGS__), __VA_ARGS__)
533 * \brief Register a field within an object with custom handlers
535 * \param sorcery Pointer to a sorcery structure
536 * \param type Type of object
537 * \param name Name of the field
538 * \param default_val Default value of the field
539 * \param config_handler Custom configuration handler
540 * \param sorcery_handler Custom sorcery handler
541 * \param multiple_handler Custom multiple handler
542 * \param flags Option type specific flags
547 #define ast_sorcery_object_field_register_custom(sorcery, type, name, default_val, config_handler, sorcery_handler, multiple_handler, flags, ...) \
548 __ast_sorcery_object_field_register(sorcery, type, name, default_val, OPT_CUSTOM_T, config_handler, sorcery_handler, multiple_handler, flags, 0, VA_NARGS(__VA_ARGS__), __VA_ARGS__);
551 * \brief Register a field within an object with custom handlers without documentation
553 * \param sorcery Pointer to a sorcery structure
554 * \param type Type of object
555 * \param name Name of the field
556 * \param default_val Default value of the field
557 * \param config_handler Custom configuration handler
558 * \param sorcery_handler Custom sorcery handler
559 * \param multiple_handler Custom multiple handler
560 * \param flags Option type specific flags
565 #define ast_sorcery_object_field_register_custom_nodoc(sorcery, type, name, default_val, config_handler, sorcery_handler, multiple_handler, flags, ...) \
566 __ast_sorcery_object_field_register(sorcery, type, name, default_val, OPT_CUSTOM_T, config_handler, sorcery_handler, multiple_handler, flags, 1, VA_NARGS(__VA_ARGS__), __VA_ARGS__);
569 * \brief Inform any wizards to load persistent objects
571 * \param sorcery Pointer to a sorcery structure
573 void ast_sorcery_load(const struct ast_sorcery *sorcery);
576 * \brief Inform any wizards of a specific object type to load persistent objects
578 * \param sorcery Pointer to a sorcery structure
579 * \param type Name of the object type to load
581 void ast_sorcery_load_object(const struct ast_sorcery *sorcery, const char *type);
584 * \brief Inform any wizards to reload persistent objects
586 * \param sorcery Pointer to a sorcery structure
588 void ast_sorcery_reload(const struct ast_sorcery *sorcery);
591 * \brief Inform any wizards of a specific object type to reload persistent objects
593 * \param sorcery Pointer to a sorcery structure
594 * \param type Name of the object type to reload
596 void ast_sorcery_reload_object(const struct ast_sorcery *sorcery, const char *type);
599 * \brief Increase the reference count of a sorcery structure
601 * \param sorcery Pointer to a sorcery structure
603 void ast_sorcery_ref(struct ast_sorcery *sorcery);
607 * \brief Create an object set (KVP list) for an object
609 * \param sorcery Pointer to a sorcery structure
610 * \param object Pointer to a sorcery object
611 * \param flags Flags indicating which handler to use and in what order.
613 * \retval non-NULL success
614 * \retval NULL if error occurred
616 * \note The returned ast_variable list must be destroyed using ast_variables_destroy
618 struct ast_variable *ast_sorcery_objectset_create2(const struct ast_sorcery *sorcery,
619 const void *object, enum ast_sorcery_field_handler_flags flags);
622 * \brief Create an object set (KVP list) for an object
624 * \param sorcery Pointer to a sorcery structure
625 * \param object Pointer to a sorcery object
627 * \retval non-NULL success
628 * \retval NULL if error occurred
630 * \note The returned ast_variable list must be destroyed using ast_variables_destroy
632 * \note This function attempts to use a field's sorcery_fields_handler first and if that
633 * doesn't exist or fails, a field's sorcery_field_handler is used. The difference is
634 * that the former may return multiple list entries for the same field and the latter will only
635 * return 1. It's up to the field itself to determine what the appropriate content is.
637 #define ast_sorcery_objectset_create(sorcery, object) \
638 ast_sorcery_objectset_create2(sorcery, object, AST_HANDLER_PREFER_LIST)
641 * \brief Create an object set in JSON format for an object
643 * \param sorcery Pointer to a sorcery structure
644 * \param object Pointer to a sorcery object
646 * \retval non-NULL success
647 * \retval NULL if error occurred
649 * \note The returned ast_json object must be unreferenced using ast_json_unref
651 struct ast_json *ast_sorcery_objectset_json_create(const struct ast_sorcery *sorcery, const void *object);
654 * \brief Apply an object set (KVP list) to an object
656 * \param sorcery Pointer to a sorcery structure
657 * \param object Pointer to a sorcery object
658 * \param objectset Object set itself
663 * \note This operation is *not* atomic. If this fails it is possible for the object to be left with a partially
664 * applied object set.
666 int ast_sorcery_objectset_apply(const struct ast_sorcery *sorcery, void *object, struct ast_variable *objectset);
669 * \brief Create a changeset given two object sets
671 * \param original Original object set
672 * \param modified Modified object set
673 * \param changes Pointer to hold any changes between the object sets
678 * \note The returned ast_variable list must be destroyed using ast_variables_destroy
680 int ast_sorcery_changeset_create(const struct ast_variable *original, const struct ast_variable *modified, struct ast_variable **changes);
683 * \brief Allocate a generic sorcery capable object
685 * \param size Size of the object
686 * \param destructor Optional destructor function
688 * \retval non-NULL success
689 * \retval NULL failure
691 void *ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor);
694 * \brief Allocate an object
696 * \param sorcery Pointer to a sorcery structure
697 * \param type Type of object to allocate
698 * \param id Optional unique identifier, if none is provided one will be generated
700 * \retval non-NULL success
701 * \retval NULL failure
703 void *ast_sorcery_alloc(const struct ast_sorcery *sorcery, const char *type, const char *id);
706 * \brief Create a copy of an object
708 * \param sorcery Pointer to a sorcery structure
709 * \param object Existing object
711 * \retval non-NULL success
712 * \retval NULL failure
714 void *ast_sorcery_copy(const struct ast_sorcery *sorcery, const void *object);
717 * \brief Create a changeset of two objects
719 * \param sorcery Pointer to a sorcery structure
720 * \param original Original object
721 * \param modified Modified object
722 * \param changes Pointer which will be populated with changes if any exist
727 * \note The returned ast_variable list must be destroyed using ast_variables_destroy
729 * \note While the objects must be of the same type they do not have to be the same object
731 int ast_sorcery_diff(const struct ast_sorcery *sorcery, const void *original, const void *modified, struct ast_variable **changes);
734 * \brief Add an observer to a specific object type
736 * \param sorcery Pointer to a sorcery structure
737 * \param type Type of object that should be observed
738 * \param callbacks Implementation of the observer interface
743 * \note You must be ready to accept observer invocations before this function is called
745 int ast_sorcery_observer_add(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks);
748 * \brief Remove an observer from a specific object type
750 * \param sorcery Pointer to a sorcery structure
751 * \param type Type of object that should no longer be observed
752 * \param callbacks Implementation of the observer interface
757 void ast_sorcery_observer_remove(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks);
760 * \brief Create and potentially persist an object using an available wizard
762 * \param sorcery Pointer to a sorcery structure
763 * \param object Pointer to a sorcery object
768 int ast_sorcery_create(const struct ast_sorcery *sorcery, void *object);
771 * \brief Retrieve an object using its unique identifier
773 * \param sorcery Pointer to a sorcery structure
774 * \param type Type of object to retrieve
775 * \param id Unique object identifier
777 * \retval non-NULL if found
778 * \retval NULL if not found
780 void *ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id);
783 * \brief Retrieve an object or multiple objects using specific fields
785 * \param sorcery Pointer to a sorcery structure
786 * \param type Type of object to retrieve
787 * \param flags Flags to control behavior
788 * \param fields Optional object fields and values to match against
790 * \retval non-NULL if found
791 * \retval NULL if not found
793 * \note If the AST_RETRIEVE_FLAG_MULTIPLE flag is specified the returned value will be an
794 * ao2_container that must be unreferenced after use.
796 * \note If the AST_RETRIEVE_FLAG_ALL flag is used you may omit fields to retrieve all objects
799 void *ast_sorcery_retrieve_by_fields(const struct ast_sorcery *sorcery, const char *type, unsigned int flags, struct ast_variable *fields);
802 * \brief Retrieve multiple objects using a regular expression on their id
804 * \param sorcery Pointer to a sorcery structure
805 * \param type Type of object to retrieve
806 * \param regex Regular expression
808 * \retval non-NULL if error occurs
809 * \retval NULL success
811 * \note The provided regex is treated as extended case sensitive.
813 struct ao2_container *ast_sorcery_retrieve_by_regex(const struct ast_sorcery *sorcery, const char *type, const char *regex);
816 * \brief Update an object
818 * \param sorcery Pointer to a sorcery structure
819 * \param object Pointer to a sorcery object
824 int ast_sorcery_update(const struct ast_sorcery *sorcery, void *object);
827 * \brief Delete an object
829 * \param sorcery Pointer to a sorcery structure
830 * \param object Pointer to a sorcery object
835 int ast_sorcery_delete(const struct ast_sorcery *sorcery, void *object);
838 * \brief Decrease the reference count of a sorcery structure
840 * \param sorcery Pointer to a sorcery structure
842 void ast_sorcery_unref(struct ast_sorcery *sorcery);
845 * \brief Get the unique identifier of a sorcery object
847 * \param object Pointer to a sorcery object
849 * \retval unique identifier
851 const char *ast_sorcery_object_get_id(const void *object);
854 * \brief Get the type of a sorcery object
856 * \param object Pointer to a sorcery object
858 * \retval type of object
860 const char *ast_sorcery_object_get_type(const void *object);
863 * \brief Get an extended field value from a sorcery object
865 * \param object Pointer to a sorcery object
866 * \param name Name of the extended field value
868 * \retval non-NULL if found
869 * \retval NULL if not found
871 * \note The returned string does NOT need to be freed and is guaranteed to remain valid for the lifetime of the object
873 const char *ast_sorcery_object_get_extended(const void *object, const char *name);
876 * \brief Set an extended field value on a sorcery object
878 * \param object Pointer to a sorcery object
879 * \param name Name of the extended field
880 * \param value Value of the extended field
885 * \note The field name MUST begin with '@' to indicate it is an extended field.
886 * \note If the extended field already exists it will be overwritten with the new value.
888 int ast_sorcery_object_set_extended(const void *object, const char *name, const char *value);
891 * \brief Sorcery object comparator based on id.
893 int ast_sorcery_object_id_compare(const void *obj_left, const void *obj_right, int flags);
896 #if defined(__cplusplus) || defined(c_plusplus)
900 #endif /* _ASTERISK_SORCERY_H */