96#ifndef _ASTERISK_SORCERY_H
97#define _ASTERISK_SORCERY_H
99#if defined(__cplusplus) || defined(c_plusplus)
107#define MAX_OBJECT_TYPE 64
110#define MAX_OBJECT_FIELD 128
249 const char *wizard_args,
void *wizard_data);
253 const char *object_type);
257 const char *object_type,
int reloaded);
261 const char *object_type,
int reloaded);
268 const char *object_type,
int reloaded);
272 const char *object_type,
int reloaded);
284 void *(*open)(
const char *data);
307 const size_t prefix_len);
356#define SORCERY_OBJECT(details) \
358 struct ast_sorcery_object_details details; \
383#define ast_sorcery_wizard_register(interface) __ast_sorcery_wizard_register(interface, AST_MODULE_SELF)
406#define ast_sorcery_open() __ast_sorcery_open(AST_MODULE, __FILE__, __LINE__, __PRETTY_FUNCTION__)
453 const char *
name,
const char *module);
455#define ast_sorcery_apply_config(sorcery, name) \
456 __ast_sorcery_apply_config((sorcery), (name), AST_MODULE)
474 const char *
type,
const char *module,
const char *
name,
const char *data);
476#define ast_sorcery_apply_default(sorcery, type, name, data) \
477 __ast_sorcery_apply_default((sorcery), (type), AST_MODULE, (name), (data))
495 const char *
type,
const char *module,
const char *
name,
const char *data,
unsigned int caching);
510#define ast_sorcery_apply_wizard_mapping(sorcery, type, name, data, caching) \
511 __ast_sorcery_apply_wizard_mapping((sorcery), (type), AST_MODULE, (name), (data), (caching));
543 const char *
type,
const char *module,
const char *
name,
const char *data,
544 unsigned int caching,
int position);
562#define ast_sorcery_insert_wizard_mapping(sorcery, type, name, data, caching, position) \
563 __ast_sorcery_insert_wizard_mapping((sorcery), (type), AST_MODULE, (name), (data), \
564 (caching), (position))
615 const char *object_type_name,
const char *module,
const char *wizard_type_name,
646#define ast_sorcery_object_type_insert_wizard(sorcery, \
647 object_type_name, wizard_type_name, wizard_args, flags, \
648 position, wizard, wizard_data) \
649 __ast_sorcery_object_type_insert_wizard((sorcery), \
650 (object_type_name), AST_MODULE, (wizard_type_name), (wizard_args), (flags), \
651 position, (wizard), (wizard_data))
678#define ast_sorcery_object_type_apply_wizard(sorcery, \
679 object_type_name, wizard_type_name, wizard_args, flags, \
680 wizard, wizard_data) \
681 __ast_sorcery_object_type_insert_wizard((sorcery), \
682 (object_type_name), AST_MODULE, (wizard_type_name), (wizard_args), (flags), \
683 AST_SORCERY_WIZARD_POSITION_LAST, (wizard), (wizard_data))
704 const char *object_type_name,
const char *module,
const char *wizard_type_name,
705 const char *wizard_args);
724#define ast_sorcery_object_type_remove_wizard(sorcery, object_type_name, \
725 wizard_type_name, wizard_args) \
726 __ast_sorcery_object_type_remove_wizard((sorcery), (object_type_name), \
727 AST_MODULE, (wizard_type_name), (wizard_args))
743 const char *
type,
const char *module,
const char *
name);
757#define ast_sorcery_remove_wizard_mapping(sorcery, type, name) \
758 __ast_sorcery_remove_wizard_mapping((sorcery), (type), AST_MODULE, (name))
837#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply) \
838 __ast_sorcery_object_register((sorcery), (type), 0, 1, (alloc), (transform), (apply))
852#define ast_sorcery_object_register_no_reload(sorcery, type, alloc, transform, apply) \
853 __ast_sorcery_object_register((sorcery), (type), 0, 0, (alloc), (transform), (apply))
867#define ast_sorcery_internal_object_register(sorcery, type, alloc, transform, apply) \
868 __ast_sorcery_object_register((sorcery), (type), 1, 1, (alloc), (transform), (apply))
940 unsigned int alias,
size_t argc, ...);
955#define ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags, ...) \
956 __ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, NULL, NULL, NULL, flags, 0, 0, VA_NARGS(__VA_ARGS__), __VA_ARGS__)
971#define ast_sorcery_object_field_register_alias(sorcery, type, name, default_val, opt_type, flags, ...) \
972 __ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, NULL, NULL, NULL, flags, 1, 1, VA_NARGS(__VA_ARGS__), __VA_ARGS__)
987#define ast_sorcery_object_field_register_nodoc(sorcery, type, name, default_val, opt_type, flags, ...) \
988 __ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, NULL, NULL, NULL, flags, 1, 0, VA_NARGS(__VA_ARGS__), __VA_ARGS__)
1005#define ast_sorcery_object_field_register_custom(sorcery, type, name, default_val, config_handler, sorcery_handler, multiple_handler, flags, ...) \
1006 __ast_sorcery_object_field_register(sorcery, type, name, default_val, OPT_CUSTOM_T, config_handler, sorcery_handler, multiple_handler, flags, 0, 0, VA_NARGS(__VA_ARGS__), __VA_ARGS__);
1023#define ast_sorcery_object_field_register_custom_alias(sorcery, type, name, default_val, config_handler, sorcery_handler, multiple_handler, flags, ...) \
1024 __ast_sorcery_object_field_register(sorcery, type, name, default_val, OPT_CUSTOM_T, config_handler, sorcery_handler, multiple_handler, flags, 1, 1, VA_NARGS(__VA_ARGS__), __VA_ARGS__);
1041#define ast_sorcery_object_field_register_custom_nodoc(sorcery, type, name, default_val, config_handler, sorcery_handler, multiple_handler, flags, ...) \
1042 __ast_sorcery_object_field_register(sorcery, type, name, default_val, OPT_CUSTOM_T, config_handler, sorcery_handler, multiple_handler, flags, 1, 0, VA_NARGS(__VA_ARGS__), __VA_ARGS__);
1137#define ast_sorcery_objectset_create(sorcery, object) \
1138 ast_sorcery_objectset_create2(sorcery, object, AST_HANDLER_PREFER_LIST)
1500#define ast_sorcery_unref(sorcery) \
1501 ao2_cleanup(sorcery)
1615 const char *field_name);
1626#if defined(__cplusplus) || defined(c_plusplus)
static int copy(char *infile, char *outfile)
Utility function to copy a file.
void(* ao2_destructor_fn)(void *vdoomed)
Typedef for an object destructor.
Configuration option-handling.
int(* aco_option_handler)(const struct aco_option *opt, struct ast_variable *var, void *obj)
A callback function for handling a particular option.
aco_option_type
The option types.
void *(* aco_type_item_alloc)(const char *category)
Allocate a configurable ao2 object.
static int set(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
static char prefix[MAX_PREFIX]
static struct ast_sorcery * sorcery
const char * ast_sorcery_object_get_extended(const void *object, const char *name)
Get an extended field value from a sorcery object.
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
int ast_sorcery_wizard_unregister(const struct ast_sorcery_wizard *interface)
Unregister a sorcery wizard.
void ast_sorcery_observer_remove(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks)
Remove an observer from a specific object type.
int ast_sorcery_object_fields_register(struct ast_sorcery *sorcery, const char *type, const char *regex, aco_option_handler config_handler, sorcery_fields_handler sorcery_handler)
Register a regex for multiple fields within an object.
int ast_sorcery_object_set_extended(const void *object, const char *name, const char *value)
Set an extended field value on a sorcery object.
void ast_sorcery_instance_observer_remove(struct ast_sorcery *sorcery, const struct ast_sorcery_instance_observer *callbacks)
Remove an observer from a sorcery instance.
enum ast_sorcery_apply_result __ast_sorcery_apply_default(struct ast_sorcery *sorcery, const char *type, const char *module, const char *name, const char *data)
Apply default object wizard mappings.
struct ast_variable *(* sorcery_transform_handler)(struct ast_variable *set)
A callback function for performing a transformation on an object set.
ast_sorcery_retrieve_flags
Retrieval flags.
@ AST_RETRIEVE_FLAG_MULTIPLE
Return all matching objects.
@ AST_RETRIEVE_FLAG_DEFAULT
Default retrieval flags.
@ AST_RETRIEVE_FLAG_ALL
Perform no matching, return all objects.
void ast_sorcery_load(const struct ast_sorcery *sorcery)
Inform any wizards to load persistent objects.
void ast_sorcery_wizard_observer_remove(struct ast_sorcery_wizard *interface, const struct ast_sorcery_wizard_observer *callbacks)
Remove an observer from a sorcery wizard.
const char * ast_sorcery_get_module(const struct ast_sorcery *sorcery)
Get the module that has opened the provided sorcery instance.
const char * ast_sorcery_object_get_type(const void *object)
Get the type of a sorcery object.
int(* sorcery_fields_handler)(const void *obj, struct ast_variable **fields)
A callback function for translating multiple values into an ast_variable list.
void ast_sorcery_object_set_copy_handler(struct ast_sorcery *sorcery, const char *type, sorcery_copy_handler copy)
Set the copy handler for an object type.
void ast_sorcery_object_set_has_dynamic_contents(const void *object)
Set the dynamic contents flag on a sorcery object.
int ast_sorcery_create(const struct ast_sorcery *sorcery, void *object)
Create and potentially persist an object using an available wizard.
struct ast_sorcery_object_type * ast_sorcery_get_object_type(const struct ast_sorcery *sorcery, const char *type)
Get the sorcery object type given a type name.
int ast_sorcery_diff(const struct ast_sorcery *sorcery, const void *original, const void *modified, struct ast_variable **changes)
Create a changeset of two objects.
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
struct ast_sorcery * __ast_sorcery_open(const char *module, const char *file, int line, const char *func)
void ast_sorcery_reload(const struct ast_sorcery *sorcery)
Inform any wizards to reload persistent objects.
int ast_sorcery_get_wizard_mapping_count(struct ast_sorcery *sorcery, const char *type)
Return the number of wizards mapped to an object type.
struct ao2_container * ast_sorcery_retrieve_by_regex(const struct ast_sorcery *sorcery, const char *type, const char *regex)
Retrieve multiple objects using a regular expression on their id.
int __ast_sorcery_wizard_register(const struct ast_sorcery_wizard *interface, struct ast_module *module)
Register a sorcery wizard.
int ast_sorcery_observer_add(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks)
Add an observer to a specific object type.
enum ast_sorcery_apply_result __ast_sorcery_insert_wizard_mapping(struct ast_sorcery *sorcery, const char *type, const char *module, const char *name, const char *data, unsigned int caching, int position)
Insert an additional object wizard mapping at a specific position in the wizard list.
void ast_sorcery_force_reload(const struct ast_sorcery *sorcery)
Inform any wizards to reload persistent objects, even if no changes determined.
void ast_sorcery_load_object(const struct ast_sorcery *sorcery, const char *type)
Inform any wizards of a specific object type to load persistent objects.
int(* sorcery_apply_handler)(const struct ast_sorcery *sorcery, void *obj)
A callback function for when an object set is successfully applied to an object.
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
int ast_sorcery_object_unregister(struct ast_sorcery *sorcery, const char *type)
Unregister an object type.
int __ast_sorcery_remove_wizard_mapping(struct ast_sorcery *sorcery, const char *type, const char *module, const char *name)
Remove an object wizard mapping.
int(* sorcery_diff_handler)(const void *original, const void *modified, struct ast_variable **changes)
A callback function for generating a changeset between two objects.
int ast_sorcery_object_id_compare(void *obj, void *arg, int flags)
ao2 object comparator based on sorcery id.
int(* sorcery_copy_handler)(const void *src, void *dst)
A callback function for copying the contents of one object to another.
unsigned int ast_sorcery_object_has_dynamic_contents(const void *object)
Get whether an object contains dynamic contents or not.
void ast_sorcery_ref(struct ast_sorcery *sorcery)
Increase the reference count of a sorcery structure.
int __ast_sorcery_object_field_register(struct ast_sorcery *sorcery, const char *type, const char *name, const char *default_val, enum aco_option_type opt_type, aco_option_handler config_handler, sorcery_field_handler sorcery_handler, sorcery_fields_handler multiple_handler, unsigned int flags, unsigned int no_doc, unsigned int alias, size_t argc,...)
Register a field within an object.
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)
Register an object type.
int ast_sorcery_changeset_create(const struct ast_variable *original, const struct ast_variable *modified, struct ast_variable **changes)
Create a changeset given two object sets.
ast_sorcery_wizard_position
Pre-defined locations to insert at.
@ AST_SORCERY_WIZARD_POSITION_FIRST
@ AST_SORCERY_WIZARD_POSITION_LAST
enum ast_sorcery_apply_result __ast_sorcery_apply_config(struct ast_sorcery *sorcery, const char *name, const char *module)
Apply configured wizard mappings.
int ast_sorcery_is_object_field_registered(const struct ast_sorcery_object_type *object_type, const char *field_name)
Determine if a particular object field has been registered with sorcery.
void * ast_sorcery_alloc(const struct ast_sorcery *sorcery, const char *type, const char *id)
Allocate an object.
int ast_sorcery_object_id_sort(const void *obj, const void *arg, int flags)
ao2 object sorter based on sorcery id.
const struct timeval ast_sorcery_object_get_created(const void *object)
Get when the sorcery object was created.
void * ast_sorcery_lockable_alloc(size_t size, ao2_destructor_fn destructor, void *lockobj)
Allocate a generic sorcery capable object with locking.
int ast_sorcery_update(const struct ast_sorcery *sorcery, void *object)
Update an object.
int ast_sorcery_objectset_apply(const struct ast_sorcery *sorcery, void *object, struct ast_variable *objectset)
Apply an object set (KVP list) to an object.
int ast_sorcery_get_wizard_mapping(struct ast_sorcery *sorcery, const char *type, int index, struct ast_sorcery_wizard **wizard, void **data)
By index, return a wizard mapped to an object type.
ast_sorcery_field_handler_flags
Field handler flags.
@ AST_HANDLER_PREFER_STRING
Try both handlers, string first.
@ AST_HANDLER_PREFER_LIST
Try both handlers, list first.
@ AST_HANDLER_ONLY_LIST
Use list handler only.
@ AST_HANDLER_ONLY_STRING
Use string handler only.
void ast_sorcery_force_reload_object(const struct ast_sorcery *sorcery, const char *type)
Inform any wizards of a specific object type to reload persistent objects even if no changes determin...
int(* sorcery_field_handler)(const void *obj, const intptr_t *args, char **buf)
A callback function for translating a value into a string.
enum ast_sorcery_apply_result __ast_sorcery_apply_wizard_mapping(struct ast_sorcery *sorcery, const char *type, const char *module, const char *name, const char *data, unsigned int caching)
Apply additional object wizard mappings.
int __ast_sorcery_object_type_remove_wizard(struct ast_sorcery *sorcery, const char *object_type_name, const char *module, const char *wizard_type_name, const char *wizard_args)
Remove an object wizard mapping.
int ast_sorcery_wizard_observer_add(struct ast_sorcery_wizard *wizard, const struct ast_sorcery_wizard_observer *callbacks)
Add an observer to a sorcery wizard.
void ast_sorcery_global_observer_remove(const struct ast_sorcery_global_observer *callbacks)
Remove a global observer from sorcery.
struct ast_json * ast_sorcery_objectset_json_create(const struct ast_sorcery *sorcery, const void *object)
Create an object set in JSON format for an object.
int ast_sorcery_global_observer_add(const struct ast_sorcery_global_observer *callbacks)
Add a global observer to sorcery.
void ast_sorcery_reload_object(const struct ast_sorcery *sorcery, const char *type)
Inform any wizards of a specific object type to reload persistent objects.
struct ast_variable * ast_sorcery_objectset_create2(const struct ast_sorcery *sorcery, const void *object, enum ast_sorcery_field_handler_flags flags)
Create an object set (KVP list) for an object.
int ast_sorcery_is_stale(const struct ast_sorcery *sorcery, void *object)
Determine if a sorcery object is stale with respect to its backing datastore.
int ast_sorcery_instance_observer_add(struct ast_sorcery *sorcery, const struct ast_sorcery_instance_observer *callbacks)
Add an observer to a sorcery instance.
int ast_sorcery_object_id_hash(const void *obj, int flags)
ao2 object hasher based on sorcery id.
void * ast_sorcery_retrieve_by_fields(const struct ast_sorcery *sorcery, const char *type, unsigned int flags, struct ast_variable *fields)
Retrieve an object or multiple objects using specific fields.
int ast_sorcery_object_set_congestion_levels(struct ast_sorcery *sorcery, const char *type, long low_water, long high_water)
Set the high and low alert water marks of the sorcery object type.
struct ast_sorcery * ast_sorcery_retrieve_by_module_name(const char *module_name)
Retrieves an existing sorcery instance by module name.
int ast_sorcery_delete(const struct ast_sorcery *sorcery, void *object)
Delete an object.
void * ast_sorcery_copy(const struct ast_sorcery *sorcery, const void *object)
Create a copy of an object.
ast_sorcery_wizard_apply_flags
Wizard Apply Flags.
@ AST_SORCERY_WIZARD_APPLY_NONE
@ AST_SORCERY_WIZARD_APPLY_ALLOW_DUPLICATE
@ AST_SORCERY_WIZARD_APPLY_READONLY
@ AST_SORCERY_WIZARD_APPLY_CACHING
struct ao2_container * ast_sorcery_retrieve_by_prefix(const struct ast_sorcery *sorcery, const char *type, const char *prefix, const size_t prefix_len)
Retrieve multiple objects whose id begins with the specified prefix.
int ast_sorcery_init(void)
Initialize the sorcery API.
enum ast_sorcery_apply_result __ast_sorcery_object_type_insert_wizard(struct ast_sorcery *sorcery, const char *object_type_name, const char *module, const char *wizard_type_name, const char *wizard_args, enum ast_sorcery_wizard_apply_flags flags, int position, struct ast_sorcery_wizard **wizard, void **wizard_data)
Insert an additional object wizard mapping at a specific position in the wizard list returning wizard...
@ AST_SORCERY_APPLY_SUCCESS
@ AST_SORCERY_APPLY_NO_CONFIGURATION
@ AST_SORCERY_APPLY_DUPLICATE
@ AST_SORCERY_APPLY_DEFAULT_UNNECESSARY
void ast_sorcery_object_set_diff_handler(struct ast_sorcery *sorcery, const char *type, sorcery_diff_handler diff)
Set the diff handler for an object type.
Abstract JSON element (object, array, string, int, ...).
Interface for the global sorcery observer.
void(* wizard_unregistering)(const char *name, const struct ast_sorcery_wizard *wizard)
Callback before a wizard is unregistered.
void(* instance_destroying)(const char *name, struct ast_sorcery *sorcery)
Callback before an instance is destroyed.
void(* wizard_registered)(const char *name, const struct ast_sorcery_wizard *wizard)
Callback after an wizard is registered.
void(* instance_created)(const char *name, struct ast_sorcery *sorcery)
Callback after an instance is created.
Interface for the sorcery instance observer.
void(* instance_loaded)(const char *name, const struct ast_sorcery *sorcery, int reloaded)
Callback after instance is loaded/reloaded.
void(* object_type_registered)(const char *name, struct ast_sorcery *sorcery, const char *object_type)
Callback after any object_type is registered.
void(* object_type_loaded)(const char *name, const struct ast_sorcery *sorcery, const char *object_type, int reloaded)
Callback after any object_type is loaded/reloaded.
void(* wizard_mapped)(const char *name, struct ast_sorcery *sorcery, const char *object_type, struct ast_sorcery_wizard *wizard, const char *wizard_args, void *wizard_data)
Callback after a wizard is mapped to an object_type.
void(* object_type_loading)(const char *name, const struct ast_sorcery *sorcery, const char *object_type, int reloaded)
Callback before any object_type is loaded/reloaded.
void(* instance_loading)(const char *name, const struct ast_sorcery *sorcery, int reloaded)
Callback before instance is loaded/reloaded.
Structure which contains details about a sorcery object.
struct ast_sorcery_object * object
Pointer to internal sorcery object information.
Structure for registered object type.
Structure for internal sorcery object information.
Interface for a sorcery object type observer.
void(* loaded)(const char *object_type)
Callback for when an object type is loaded/reloaded.
void(* deleted)(const void *object)
Callback for when an object is deleted.
void(* created)(const void *object)
Callback for when an object is created.
void(* updated)(const void *object)
Callback for when an object is updated.
Interface for the sorcery wizard observer.
void(* wizard_loading)(const char *name, const struct ast_sorcery_wizard *wizard, const char *object_type, int reloaded)
Callback before a wizard is loaded/reloaded for any type.
void(* wizard_loaded)(const char *name, const struct ast_sorcery_wizard *wizard, const char *object_type, int reloaded)
Callback after a wizard is loaded/reloaded for any type.
Interface for a sorcery wizard.
void(* close)(void *data)
Callback for closing a wizard.
void(* retrieve_multiple)(const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects, const struct ast_variable *fields)
Optional callback for retrieving multiple objects using some optional field criteria.
struct ast_module * module
Pointer to the Asterisk module this wizard is implemented by.
const char * name
Name of the wizard.
void(* load)(void *data, const struct ast_sorcery *sorcery, const char *type)
Optional callback for loading persistent objects.
int(* create)(const struct ast_sorcery *sorcery, void *data, void *object)
Callback for creating an object.
int(* is_stale)(const struct ast_sorcery *sorcery, void *data, void *object)
Callback for whether or not the wizard believes the object is stale.
void(* retrieve_prefix)(const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects, const char *prefix, const size_t prefix_len)
Optional callback for retrieving multiple objects by matching their id with a prefix.
void(* force_reload)(void *data, const struct ast_sorcery *sorcery, const char *type)
Optional callback for forcing a reload to occur, even if wizard has determined no changes.
void(* retrieve_regex)(const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects, const char *regex)
Callback for retrieving multiple objects using a regex on their id.
int(* update)(const struct ast_sorcery *sorcery, void *data, void *object)
Callback for updating an object.
void(* reload)(void *data, const struct ast_sorcery *sorcery, const char *type)
Optional callback for reloading persistent objects.
Full structure for sorcery.
char * module_name
Pointer to module_name in the associated sorcery_proxy.
Structure for variables, used for configurations and for channel variables.
Universally unique identifier support.