143 }
else if (params->
prefix) {
148 }
else if (params->
fields &&
181 if (!objects || !
fields) {
203 .container = objects,
206 if (!config_objects) {
220 .container = objects,
221 .regex = &expression,
228 if (!config_objects || regcomp(&expression,
regex, REG_EXTENDED | REG_NOSUB)) {
233 regfree(&expression);
242 .container = objects,
247 if (!config_objects) {
323 const char *
id =
NULL;
324 unsigned int buckets = 0;
325 unsigned int has_dynamic_contents = 0;
339 config->configuration_invalid = 0;
364 buckets =
config->buckets;
370 if (
config->single_object && buckets > 1) {
371 ast_log(
LOG_ERROR,
"Config file '%s' could not be loaded; configuration contains more than one object of type '%s'\n",
374 config->configuration_invalid = 1;
378 ast_debug(2,
"Using bucket size of '%d' for objects of type '%s' from '%s'\n",
384 ast_log(
LOG_ERROR,
"Could not create bucket for new objects from '%s', keeping existing objects\n",
387 config->configuration_invalid = 1;
405 ast_log(
LOG_ERROR,
"Config file '%s' could not be loaded; configuration contains a duplicate object: '%s' of type '%s'\n",
408 config->configuration_invalid = 1;
415 if (
config->file_integrity) {
416 ast_log(
LOG_ERROR,
"Config file '%s' could not be loaded due to error with object '%s' of type '%s'\n",
419 config->configuration_invalid = 1;
422 ast_log(
LOG_ERROR,
"Could not create an object of type '%s' with id '%s' from configuration file '%s'\n",
424 config->configuration_invalid = 1;
434 ast_log(
LOG_NOTICE,
"Retaining existing configuration for object of type '%s' with id '%s'\n",
type,
id);
445 config->has_dynamic_contents = has_dynamic_contents;
486 if (!strcasecmp(
name,
"buckets")) {
487 if (sscanf(
value,
"%30u", &
config->buckets) != 1) {
488 ast_log(
LOG_ERROR,
"Unsupported bucket size of '%s' used for configuration file '%s', defaulting to automatic determination\n",
491 }
else if (!strcasecmp(
name,
"integrity")) {
492 if (!strcasecmp(
value,
"file")) {
493 config->file_integrity = 1;
494 }
else if (!strcasecmp(
value,
"object")) {
495 config->file_integrity = 0;
497 ast_log(
LOG_ERROR,
"Unsupported integrity value of '%s' used for configuration file '%s', defaulting to 'object'\n",
500 }
else if (!strcasecmp(
name,
"criteria")) {
506 config->criteria = criteria;
509 ast_log(
LOG_ERROR,
"Could not create criteria entry of field '%s' with value '%s' for configuration file '%s'\n",
510 field,
value, filename);
514 }
else if (!strcasecmp(
name,
"explicit_name")) {
519 ast_log(
LOG_ERROR,
"Could not create explicit name entry of '%s' for configuration file '%s'\n",
524 }
else if (!strcasecmp(
name,
"single_object")) {
526 ast_log(
LOG_ERROR,
"Could not set single object value for configuration file '%s' as the value is empty\n",
533 ast_log(
LOG_ERROR,
"Unsupported option '%s' used for configuration file '%s'\n",
name, filename);
Asterisk main include file. File version handling, generic pbx functions.
#define ast_strdup(str)
A wrapper for strdup()
#define ast_strdupa(s)
duplicate a string in memory from the stack
#define ao2_link(container, obj)
Add an object to a container.
@ AO2_ALLOC_OPT_LOCK_NOLOCK
#define ao2_global_obj_replace_unref(holder, obj)
Replace an ao2 object in the global holder, throwing away any old object.
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
#define ao2_global_obj_ref(holder)
Get a reference to the object stored in the global holder.
#define ao2_find(container, arg, flags)
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define ao2_alloc_options(data_size, destructor_fn, options)
#define ao2_global_obj_release(holder)
Release the ao2 object held in the global holder.
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
static const char config[]
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Generic (perhaps overly so) hashtable implementation Hash Table support in Asterisk.
int ast_is_prime(int num)
Determines if the specified number is prime.
static char prefix[MAX_PREFIX]
char * strsep(char **str, const char *delims)
Configuration File Parser.
const char * ast_category_get_name(const struct ast_category *category)
Return the name of the category.
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
#define ast_variable_new(name, value, filename)
#define CONFIG_STATUS_FILEUNCHANGED
#define CONFIG_STATUS_FILEINVALID
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
struct ast_variable * ast_category_first(struct ast_category *cat)
given a pointer to a category, return the root variable.
int ast_variable_lists_match(const struct ast_variable *left, const struct ast_variable *right, int exact_match)
Tests 2 variable lists to see if they match.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
@ CONFIG_FLAG_FILEUNCHANGED
struct ast_category * ast_category_browse_filtered(struct ast_config *config, const char *category_name, struct ast_category *prev, const char *filter)
Browse categories with filters.
#define ast_debug(level,...)
Log a DEBUG message.
#define ast_rwlock_init(rwlock)
wrapper for rwlock with tracking enabled
#define ast_rwlock_destroy(rwlock)
Asterisk module definitions.
@ AST_MODFLAG_GLOBAL_SYMBOLS
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
@ AST_MODPRI_REALTIME_DRIVER
@ AST_MODULE_SUPPORT_CORE
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
static struct ast_sorcery * sorcery
static int sorcery_is_criteria_met(struct ast_category *category, struct sorcery_config *config)
Internal function which determines if a category matches based on criteria.
static void * sorcery_config_retrieve_id(const struct ast_sorcery *sorcery, void *data, const char *type, const char *id)
static struct ast_sorcery_wizard config_object_wizard
static int sorcery_is_configuration_met(const struct ast_sorcery *sorcery, const char *type, struct ast_category *category, struct sorcery_config *config)
Internal function which determines if criteria has been met for considering an object set applicable.
static void sorcery_config_retrieve_prefix(const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects, const char *prefix, const size_t prefix_len)
static void sorcery_config_close(void *data)
static void sorcery_config_reload(void *data, const struct ast_sorcery *sorcery, const char *type)
static int sorcery_is_explicit_name_met(const struct ast_sorcery *sorcery, const char *type, struct ast_category *category, struct sorcery_config *config)
Internal function which determines if a category matches based on explicit name.
static void sorcery_config_internal_load(void *data, const struct ast_sorcery *sorcery, const char *type, unsigned int reload)
static int load_module(void)
static int unload_module(void)
static void * sorcery_config_open(const char *data)
static void sorcery_config_load(void *data, const struct ast_sorcery *sorcery, const char *type)
static void sorcery_config_destructor(void *obj)
Destructor function for sorcery config.
static void * sorcery_config_retrieve_fields(const struct ast_sorcery *sorcery, void *data, const char *type, const struct ast_variable *fields)
static void sorcery_config_retrieve_multiple(const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects, const struct ast_variable *fields)
static int sorcery_config_fields_cmp(void *obj, void *arg, int flags)
static void sorcery_config_retrieve_regex(const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects, const char *regex)
Sorcery Data Access Layer API.
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.
#define ast_sorcery_objectset_create(sorcery, object)
Create an object set (KVP list) for an object.
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_object_id_compare(void *obj, void *arg, int flags)
ao2 object comparator based on sorcery id.
unsigned int ast_sorcery_object_has_dynamic_contents(const void *object)
Get whether an object contains dynamic contents or not.
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.
#define ast_sorcery_wizard_register(interface)
See __ast_sorcery_wizard_register()
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_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_object_id_hash(const void *obj, int flags)
ao2 object hasher based on sorcery id.
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Structure used to handle boolean flags.
Structure for registered object type.
Interface for a sorcery wizard.
const char * name
Name of the wizard.
Full structure for sorcery.
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
Structure used for fields comparison.
const char * prefix
Prefix for matching object id.
struct ao2_container * container
Optional container to put object into.
const size_t prefix_len
Prefix length in bytes for matching object id.
const struct ast_sorcery * sorcery
Pointer to the sorcery structure.
const struct ast_variable * fields
Pointer to the fields to check.
regex_t * regex
Regular expression for checking object id.
Structure for storing configuration file sourced objects.
unsigned int has_dynamic_contents
Configuration contains at least one object with dynamic contents.
char uuid[AST_UUID_STR_LEN]
UUID for identifying us when opening a configuration file.
unsigned int single_object
Enable enforcement of a single configuration object of this type.
struct ao2_global_obj objects
Objects retrieved from the configuration file.
unsigned int configuration_invalid
Configuration is invalid in some way, force reload.
char filename[]
Filename of the configuration file.
struct ast_variable * criteria
Any specific variable criteria for considering a defined category for this object.
char * explicit_name
An explicit name for the configuration section, with it there can be only one.
unsigned int file_integrity
Enable file level integrity instead of object level.
unsigned int buckets
Number of buckets to use for objects.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Universally unique identifier support.
char * ast_uuid_generate_str(char *buf, size_t size)
Generate a UUID string.