Asterisk - The Open Source Telephony Project  21.4.1
Data Structures | Macros | Typedefs | Enumerations | Functions
include/asterisk/config.h File Reference

Configuration File Parser. More...

#include "asterisk/utils.h"
#include "asterisk/inline_api.h"

Go to the source code of this file.

Data Structures

struct  ast_config_engine
 Configuration engine structure, used to define realtime drivers. More...
 
struct  ast_variable
 Structure for variables, used for configurations and for channel variables. More...
 

Macros

#define ast_category_new_anonymous()   ast_category_new_dynamic("")
 Create a nameless category that is not backed by a file.
 
#define ast_category_new_dynamic(name)   ast_category_new(name, "", -1)
 Create a category that is not backed by a file. More...
 
#define ast_config_load(filename, flags)   ast_config_load2(filename, AST_MODULE, flags)
 Load a config file. More...
 
#define ast_variable_list_append(head, new_var)   ast_variable_list_append_hint(head, NULL, new_var)
 
#define ast_variable_new(name, value, filename)   _ast_variable_new(name, value, filename, __FILE__, __PRETTY_FUNCTION__, __LINE__)
 
#define CONFIG_STATUS_FILEINVALID   (void *)-2
 
#define CONFIG_STATUS_FILEMISSING   (void *)0
 
#define CONFIG_STATUS_FILEUNCHANGED   (void *)-1
 
#define CV_BOOL(__x, __dst)   CV_F(__x, (__dst) = ast_true(__val) )
 helper macros to assign the value to a BOOL, UINT, static string and dynamic string
 
#define CV_DSTR(__x, __dst)   CV_F(__x, ast_free(__dst); __dst = ast_strdup(__val))
 
#define CV_END   } while (0)
 close a variable parsing block
 
#define CV_F(__pattern, __body)   if (!strcasecmp((__var), __pattern)) { __body; break; }
 call a generic function if the name matches.
 
#define CV_START(__in_var, __in_val)
 the macro to open a block for variable parsing More...
 
#define CV_STR(__x, __dst)   CV_F(__x, ast_copy_string(__dst, __val, sizeof(__dst)))
 
#define CV_STRFIELD(__x, __obj, __field)   CV_F(__x, ast_string_field_set(__obj, __field, __val))
 
#define CV_UINT(__x, __dst)   CV_F(__x, (__dst) = strtoul(__val, NULL, 0) )
 

Typedefs

typedef int(* config_hook_cb) (struct ast_config *cfg)
 Callback when configuration is updated. More...
 
typedef struct ast_configconfig_load_func(const char *database, const char *table, const char *configfile, struct ast_config *config, struct ast_flags flags, const char *suggested_include_file, const char *who_asked)
 
typedef int realtime_destroy(const char *database, const char *table, const char *keyfield, const char *entity, const struct ast_variable *fields)
 
typedef struct ast_configrealtime_multi_get(const char *database, const char *table, const struct ast_variable *fields)
 
typedef int realtime_require(const char *database, const char *table, va_list ap)
 Function pointer called to ensure database schema is properly configured for realtime use. More...
 
typedef int realtime_store(const char *database, const char *table, const struct ast_variable *fields)
 
typedef int realtime_unload(const char *database, const char *table)
 Function pointer called to clear the database cache and free resources used for such. More...
 
typedef int realtime_update(const char *database, const char *table, const char *keyfield, const char *entity, const struct ast_variable *fields)
 
typedef int realtime_update2(const char *database, const char *table, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields)
 
typedef struct ast_variablerealtime_var_get(const char *database, const char *table, const struct ast_variable *fields)
 

Enumerations

enum  { CONFIG_FLAG_WITHCOMMENTS = (1 << 0), CONFIG_FLAG_FILEUNCHANGED = (1 << 1), CONFIG_FLAG_NOCACHE = (1 << 2), CONFIG_FLAG_NOREALTIME = (1 << 3) }
 
enum  ast_parse_flags {
  PARSE_TYPE = 0x000f, PARSE_INT32 = 0x0001, PARSE_UINT32 = 0x0002, PARSE_DOUBLE = 0x0003,
  PARSE_TIMELEN = 0x0006, PARSE_ADDR = 0x000e, PARSE_INADDR = 0x000f, PARSE_DEFAULT = 0x0010,
  PARSE_IN_RANGE = 0x0020, PARSE_OUT_RANGE = 0x0040, PARSE_RANGE_DEFAULTS = 0x0080, PARSE_PORT_MASK = 0x0300,
  PARSE_PORT_IGNORE = 0x0100, PARSE_PORT_REQUIRE = 0x0200, PARSE_PORT_FORBID = 0x0300
}
 Support code to parse config file arguments. More...
 
enum  config_hook_flags { butt }
 Flags that affect the behaviour of config hooks.
 
enum  config_save_flags { CONFIG_SAVE_FLAG_NONE = (0), CONFIG_SAVE_FLAG_PRESERVE_EFFECTIVE_CONTEXT = (1 << 0) }
 
enum  require_type {
  RQ_INTEGER1, RQ_UINTEGER1, RQ_INTEGER2, RQ_UINTEGER2,
  RQ_INTEGER3, RQ_UINTEGER3, RQ_INTEGER4, RQ_UINTEGER4,
  RQ_INTEGER8, RQ_UINTEGER8, RQ_CHAR, RQ_FLOAT,
  RQ_DATE, RQ_DATETIME
}
 Types used in ast_realtime_require_field.
 

Functions

struct ast_variable_ast_variable_new (const char *name, const char *value, const char *filename, const char *file, const char *function, int lineno)
 
void ast_category_append (struct ast_config *config, struct ast_category *category)
 Appends a category to a config. More...
 
char * ast_category_browse (struct ast_config *config, const char *prev_name)
 Browse categories. More...
 
struct ast_categoryast_category_browse_filtered (struct ast_config *config, const char *category_name, struct ast_category *prev, const char *filter)
 Browse categories with filters. More...
 
struct ast_categoryast_category_delete (struct ast_config *cfg, struct ast_category *cat)
 Delete a category. More...
 
void ast_category_destroy (struct ast_category *cat)
 
struct ast_variableast_category_detach_variables (struct ast_category *cat)
 
int ast_category_empty (struct ast_category *category)
 Removes and destroys all variables in a category. More...
 
int ast_category_exist (const struct ast_config *config, const char *category_name, const char *filter)
 Check for category duplicates. More...
 
struct ast_variableast_category_first (struct ast_category *cat)
 given a pointer to a category, return the root variable. More...
 
struct ast_categoryast_category_get (const struct ast_config *config, const char *category_name, const char *filter)
 Retrieve a category if it exists. More...
 
const char * ast_category_get_name (const struct ast_category *category)
 Return the name of the category. More...
 
struct ast_strast_category_get_templates (const struct ast_category *category)
 Return the template names this category inherits from. More...
 
int ast_category_inherit (struct ast_category *existing, const struct ast_category *base)
 Applies base (template) to category. More...
 
int ast_category_insert (struct ast_config *config, struct ast_category *cat, const char *match)
 Inserts new category. More...
 
int ast_category_is_template (const struct ast_category *category)
 Check if category is a template. More...
 
struct ast_categoryast_category_new (const char *name, const char *in_file, int lineno)
 Create a category. More...
 
struct ast_categoryast_category_new_template (const char *name, const char *in_file, int lineno)
 Create a category making it a template. More...
 
void ast_category_rename (struct ast_category *cat, const char *name)
 
struct ast_variableast_category_root (struct ast_config *config, char *cat)
 returns the root ast_variable of a config More...
 
int ast_check_realtime (const char *family)
 Check if realtime engine is configured for family. More...
 
struct ast_configast_config_copy (const struct ast_config *orig)
 Copies the contents of one ast_config into another. More...
 
void ast_config_destroy (struct ast_config *cfg)
 Destroys a config. More...
 
int ast_config_engine_deregister (struct ast_config_engine *del)
 Deregister config engine. More...
 
int ast_config_engine_register (struct ast_config_engine *newconfig)
 Register config engine. More...
 
struct ast_categoryast_config_get_current_category (const struct ast_config *cfg)
 Retrieve the current category name being built. More...
 
int ast_config_hook_register (const char *name, const char *filename, const char *module, enum config_hook_flags flags, config_hook_cb hook)
 Register a config hook for a particular file and module. More...
 
void ast_config_hook_unregister (const char *name)
 Unregister a config hook. More...
 
struct ast_configast_config_internal_load (const char *configfile, struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl_file, const char *who_asked)
 
struct ast_configast_config_load2 (const char *filename, const char *who_asked, struct ast_flags flags)
 Load a config file. More...
 
struct ast_configast_config_new (void)
 Create a new base configuration structure.
 
const char * ast_config_option (struct ast_config *cfg, const char *cat, const char *var)
 Retrieve a configuration variable within the configuration set. More...
 
void ast_config_set_current_category (struct ast_config *cfg, const struct ast_category *cat)
 Set the category within the configuration as being current. More...
 
void ast_config_sort_categories (struct ast_config *config, int descending, int(*comparator)(struct ast_category *p, struct ast_category *q))
 Sorts categories in a config in the order of a numerical value contained within them. More...
 
int ast_config_text_file_save (const char *filename, const struct ast_config *cfg, const char *generator)
 Save a config text file preserving the pre 13.2 behavior. More...
 
int ast_config_text_file_save2 (const char *filename, const struct ast_config *cfg, const char *generator, uint32_t flags)
 Save a config text file. More...
 
int ast_destroy_realtime (const char *family, const char *keyfield, const char *lookup,...) attribute_sentinel
 Destroy realtime configuration. More...
 
int ast_destroy_realtime_fields (const char *family, const char *keyfield, const char *lookup, const struct ast_variable *fields)
 Destroy realtime configuration. More...
 
struct ast_config_includeast_include_find (struct ast_config *conf, const char *included_file)
 
struct ast_config_includeast_include_new (struct ast_config *conf, const char *from_file, const char *included_file, int is_exec, const char *exec_file, int from_lineno, char *real_included_file_name, int real_included_file_name_size)
 
void ast_include_rename (struct ast_config *conf, const char *from_file, const char *to_file)
 
struct ast_variableast_load_realtime (const char *family,...) attribute_sentinel
 
struct ast_variableast_load_realtime_all (const char *family,...) attribute_sentinel
 
struct ast_variableast_load_realtime_all_fields (const char *family, const struct ast_variable *fields)
 
struct ast_variableast_load_realtime_fields (const char *family, const struct ast_variable *fields)
 Retrieve realtime configuration. More...
 
struct ast_configast_load_realtime_multientry (const char *family,...) attribute_sentinel
 Retrieve realtime configuration. More...
 
struct ast_configast_load_realtime_multientry_fields (const char *family, const struct ast_variable *fields)
 Retrieve realtime configuration. More...
 
int ast_parse_arg (const char *arg, enum ast_parse_flags flags, void *p_result,...)
 The argument parsing routine. More...
 
char * ast_realtime_decode_chunk (char *chunk)
 Remove standard encoding from realtime values, which ensures that a semicolon embedded within a single value is not treated upon retrieval as multiple values. More...
 
int ast_realtime_enabled (void)
 Check if there's any realtime engines loaded.
 
char * ast_realtime_encode_chunk (struct ast_str **dest, ssize_t maxlen, const char *chunk)
 Encodes a chunk of data for realtime. More...
 
int ast_realtime_is_mapping_defined (const char *family)
 Determine if a mapping exists for a given family. More...
 
int ast_realtime_require_field (const char *family,...) attribute_sentinel
 Inform realtime what fields that may be stored. More...
 
int ast_rq_is_int (require_type type)
 Check if require type is an integer type.
 
int ast_store_realtime (const char *family,...) attribute_sentinel
 Create realtime configuration. More...
 
int ast_store_realtime_fields (const char *family, const struct ast_variable *fields)
 Create realtime configuration. More...
 
int ast_unload_realtime (const char *family)
 Release any resources cached for a realtime family. More...
 
int ast_update2_realtime (const char *family,...) attribute_sentinel
 Update realtime configuration. More...
 
int ast_update2_realtime_fields (const char *family, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields)
 Update realtime configuration. More...
 
int ast_update_realtime (const char *family, const char *keyfield, const char *lookup,...) attribute_sentinel
 Update realtime configuration. More...
 
int ast_update_realtime_fields (const char *family, const char *keyfield, const char *lookup, const struct ast_variable *fields)
 Update realtime configuration. More...
 
void ast_variable_append (struct ast_category *category, struct ast_variable *variable)
 
struct ast_variableast_variable_browse (const struct ast_config *config, const char *category_name)
 
struct ast_variableast_variable_browse_filtered (const struct ast_config *config, const char *category_name, const char *filter)
 Browse variables. More...
 
int ast_variable_delete (struct ast_category *category, const char *variable, const char *match, const char *line)
 
const char * ast_variable_find (const struct ast_category *category, const char *variable)
 Gets a variable value from a specific category structure by name. More...
 
const char * ast_variable_find_in_list (const struct ast_variable *list, const char *variable)
 Gets the value of a variable from a variable list by name. More...
 
const char * ast_variable_find_last_in_list (const struct ast_variable *list, const char *variable)
 Gets the value of the LAST occurrence of a variable from a variable list. More...
 
const struct ast_variableast_variable_find_variable_in_list (const struct ast_variable *list, const char *variable_name)
 Gets a variable from a variable list by name. More...
 
void ast_variable_insert (struct ast_category *category, struct ast_variable *variable, const char *line)
 
struct ast_variableast_variable_list_append_hint (struct ast_variable **head, struct ast_variable *search_hint, struct ast_variable *new_var)
 Appends a variable list to the end of another list. More...
 
struct ast_variableast_variable_list_from_quoted_string (const char *input, const char *item_separator, const char *name_value_separator, const char *quote_str)
 Parse a string into an ast_variable list. The reverse of ast_variable_list_join. More...
 
struct ast_variableast_variable_list_from_string (const char *input, const char *item_separator, const char *name_value_separator)
 Parse a string into an ast_variable list. The reverse of ast_variable_list_join. More...
 
struct ast_strast_variable_list_join (const struct ast_variable *head, const char *item_separator, const char *name_value_separator, const char *quote_char, struct ast_str **str)
 Join an ast_variable list with specified separators and quoted values. More...
 
int ast_variable_list_replace (struct ast_variable **head, struct ast_variable *replacement)
 Replace a variable in the given list with a new value. More...
 
int ast_variable_list_replace_variable (struct ast_variable **head, struct ast_variable *oldvar, struct ast_variable *newvar)
 Replace a variable in the given list with a new variable. More...
 
struct ast_variableast_variable_list_sort (struct ast_variable *head)
 Performs an in-place sort on the variable list by ascending name. More...
 
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. More...
 
const char * ast_variable_retrieve (struct ast_config *config, const char *category, const char *variable)
 
const char * ast_variable_retrieve_filtered (struct ast_config *config, const char *category, const char *variable, const char *filter)
 Gets a variable by context and variable names. More...
 
int ast_variable_update (struct ast_category *category, const char *variable, const char *value, const char *match, unsigned int object)
 Update variable value within a config. More...
 
void ast_variables_destroy (struct ast_variable *var)
 Free variable list. More...
 
struct ast_variableast_variables_dup (struct ast_variable *var)
 Duplicate variable list. More...
 
int ast_variables_match (const struct ast_variable *left, const struct ast_variable *right)
 Tests 2 variable values to see if they match. More...
 
struct ast_variableast_variables_reverse (struct ast_variable *var)
 Reverse a variable list. More...
 
int register_config_cli (void)
 Exposed initialization method for core process. More...
 

Detailed Description

Configuration File Parser.

Definition in file include/asterisk/config.h.

Macro Definition Documentation

#define ast_category_new_dynamic (   name)    ast_category_new(name, "", -1)

Create a category that is not backed by a file.

Parameters
namename of new category

Definition at line 833 of file include/asterisk/config.h.

Referenced by config_ldap().

#define ast_config_load (   filename,
  flags 
)    ast_config_load2(filename, AST_MODULE, flags)

Load a config file.

Parameters
filenamepath of file to open. If no preceding '/' character, path is considered relative to AST_CONFIG_DIR
flagsOptional flags: CONFIG_FLAG_WITHCOMMENTS - load the file with comments intact; CONFIG_FLAG_FILEUNCHANGED - check the file mtime and return CONFIG_STATUS_FILEUNCHANGED if the mtime is the same; or CONFIG_FLAG_NOCACHE - don't cache file mtime (main purpose of this option is to save memory on temporary files).

Create a config structure from a given configuration file.

Returns
an ast_config data structure on success
Return values
NULLon error

Definition at line 179 of file include/asterisk/config.h.

Referenced by aco_process_config(), advanced_options(), conf_exec(), forward_message(), handle_cli_dialplan_save(), load_config(), load_config_force(), load_module(), make_email_file(), message_range_and_existence_check(), notify_new_message(), parse_config(), pbx_load_users(), reload(), reload_followme(), reload_queue_rules(), reload_queues(), set_config(), vm_change_password(), vm_forwardoptions(), and vm_msg_snapshot_create().

#define CV_START (   __in_var,
  __in_val 
)
Value:
do { \
const char *__var = __in_var; \
const char *__val = __in_val;

the macro to open a block for variable parsing

Definition at line 1278 of file include/asterisk/config.h.

Referenced by store_config_core().

Typedef Documentation

typedef int(* config_hook_cb) (struct ast_config *cfg)

Callback when configuration is updated.

Parameters
cfgA copy of the configuration that is being changed. This MUST be freed by the callback before returning.

Definition at line 1114 of file include/asterisk/config.h.

typedef int realtime_require(const char *database, const char *table, va_list ap)

Function pointer called to ensure database schema is properly configured for realtime use.

Since
1.6.1

Definition at line 121 of file include/asterisk/config.h.

typedef int realtime_unload(const char *database, const char *table)

Function pointer called to clear the database cache and free resources used for such.

Since
1.6.1

Definition at line 127 of file include/asterisk/config.h.

Enumeration Type Documentation

anonymous enum

Options for ast_config_load()

Enumerator
CONFIG_FLAG_WITHCOMMENTS 

Load the configuration, including comments

CONFIG_FLAG_FILEUNCHANGED 

On a reload, give us a -1 if the file hasn't changed.

CONFIG_FLAG_NOCACHE 

Don't attempt to cache mtime on this config file.

CONFIG_FLAG_NOREALTIME 

Don't attempt to load from realtime (typically called from a realtime driver dependency)

Definition at line 39 of file include/asterisk/config.h.

39  {
40  /*! Load the configuration, including comments */
41  CONFIG_FLAG_WITHCOMMENTS = (1 << 0),
42  /*! On a reload, give us a -1 if the file hasn't changed. */
43  CONFIG_FLAG_FILEUNCHANGED = (1 << 1),
44  /*! Don't attempt to cache mtime on this config file. */
45  CONFIG_FLAG_NOCACHE = (1 << 2),
46  /*! Don't attempt to load from realtime (typically called from a realtime driver dependency) */
47  CONFIG_FLAG_NOREALTIME = (1 << 3),
48 };

Support code to parse config file arguments.

The function ast_parse_arg() provides a generic interface to parse strings (e.g. numbers, network addresses and so on) in a flexible way, e.g. by doing proper error and bound checks, provide default values, and so on. The function (described later) takes a string as an argument, a set of flags to specify the result format and checks to perform, a pointer to the result, and optionally some additional arguments.

Returns
0 on success, != 0 otherwise.

Definition at line 1159 of file include/asterisk/config.h.

1159  {
1160  /* low 4 bits of flags are used for the operand type */
1161  PARSE_TYPE = 0x000f,
1162  /* numeric types, with optional default value and bound checks.
1163  * Additional arguments are passed by value.
1164  */
1165  PARSE_INT32 = 0x0001,
1166  PARSE_UINT32 = 0x0002,
1167  PARSE_DOUBLE = 0x0003,
1168 #if 0 /* not supported yet */
1169  PARSE_INT16 = 0x0004,
1170  PARSE_UINT16 = 0x0005,
1171 #endif
1172 
1173  /* Returns an int processed by ast_app_parse_timelen.
1174  * The first argument is an enum ast_timelen value (required).
1175  */
1176  PARSE_TIMELEN = 0x0006,
1177 
1178  /* Returns a struct ast_sockaddr, with optional default value
1179  * (passed by reference) and port handling (accept, ignore,
1180  * require, forbid). The format is 'ipaddress[:port]'. IPv6 address
1181  * literals need square brackets around them if a port is specified.
1182  */
1183  PARSE_ADDR = 0x000e,
1184 
1185  /* Returns a struct sockaddr_in, with optional default value
1186  * (passed by reference) and port handling (accept, ignore,
1187  * require, forbid). The format is 'host.name[:port]'
1188  */
1189  PARSE_INADDR = 0x000f,
1190 
1191  /* Other data types can be added as needed */
1192 
1193  /* If PARSE_DEFAULT is set, next argument is a default value
1194  * which is returned in case of error. The argument is passed
1195  * by value in case of numeric types, by reference in other cases.
1196  */
1197  PARSE_DEFAULT = 0x0010, /* assign default on error */
1198 
1199  /* Request a range check, applicable to numbers. Two additional
1200  * arguments are passed by value, specifying the low-high end of
1201  * the range (inclusive). An error is returned if the value
1202  * is outside or inside the range, respectively.
1203  */
1204  PARSE_IN_RANGE = 0x0020, /* accept values inside a range */
1205  PARSE_OUT_RANGE = 0x0040, /* accept values outside a range */
1206  PARSE_RANGE_DEFAULTS = 0x0080, /* default to range min/max on range error */
1207 
1208  /* Port handling, for ast_sockaddr. accept/ignore/require/forbid
1209  * port number after the hostname or address.
1210  */
1211  PARSE_PORT_MASK = 0x0300, /* 0x000: accept port if present */
1212  PARSE_PORT_IGNORE = 0x0100, /* 0x100: ignore port if present */
1213  PARSE_PORT_REQUIRE = 0x0200, /* 0x200: require port number */
1214  PARSE_PORT_FORBID = 0x0300, /* 0x100: forbid port number */
1215 };

Flags for ast_config_text_file_save2()

Enumerator
CONFIG_SAVE_FLAG_PRESERVE_EFFECTIVE_CONTEXT 

Insure a context doesn't effectively change if a template changes (pre 13.2 behavior)

Definition at line 52 of file include/asterisk/config.h.

52  {
53  CONFIG_SAVE_FLAG_NONE = (0),
54  /*! Insure a context doesn't effectively change if a template changes (pre 13.2 behavior) */
56 };

Function Documentation

static void ast_category_append ( struct ast_config config,
struct ast_category category 
)

Appends a category to a config.

Parameters
configwhich config to use
categorycategory to insert

Definition at line 2833 of file extconf.c.

References ast_category_append(), ast_config::last, ast_category::next, ast_category::prev, and ast_config::root.

Referenced by append_row_to_cfg(), ast_category_append(), ast_config_copy(), build_cfg(), config_ldap(), handle_updates(), process_text_line(), realtime_multi_curl(), realtime_multi_ldap(), and realtime_multi_odbc().

2834 {
2835  if (config->last)
2836  config->last->next = category;
2837  else
2838  config->root = category;
2839  config->last = category;
2840  config->current = category;
2841 }
struct ast_category * next
Definition: main/config.c:246
struct ast_category * last
Definition: main/config.c:253
struct ast_category * root
Definition: main/config.c:251
static char * ast_category_browse ( struct ast_config config,
const char *  prev_name 
)

Browse categories.

Parameters
configWhich config structure you wish to "browse"
prev_nameA pointer to a previous category name.

This function is kind of non-intuitive in it's use. To begin, one passes NULL as the second argument. It will return a pointer to the string of the first category in the file. From here on after, one must then pass the previous usage's return value as the second pointer, and it will return a pointer to the category name afterwards.

Return values
acategory name on success
NULLon failure/no-more-categories
Note
ast_category_browse maintains internal state. Therefore is not thread safe, cannot be called recursively, and it is not safe to add or remove categories while browsing. ast_category_browse_filtered does not have these restrictions.

Definition at line 3326 of file extconf.c.

References ast_category_browse(), ast_config::last_browse, ast_category::next, and ast_config::root.

Referenced by __queues_show(), ast_category_browse(), ast_cli_perms_init(), conf_exec(), find_queue_by_name_rt(), load_config(), load_indications(), load_realtime_rules(), parse_config(), pbx_load_users(), reload_followme(), reload_queue_rules(), reload_queues(), set_config(), test_config_validity(), and vm_change_password().

3327 {
3328  struct ast_category *cat = NULL;
3329 
3330  if (prev && config->last_browse && (config->last_browse->name == prev))
3331  cat = config->last_browse->next;
3332  else if (!prev && config->root)
3333  cat = config->root;
3334  else if (prev) {
3335  for (cat = config->root; cat; cat = cat->next) {
3336  if (cat->name == prev) {
3337  cat = cat->next;
3338  break;
3339  }
3340  }
3341  if (!cat) {
3342  for (cat = config->root; cat; cat = cat->next) {
3343  if (!strcasecmp(cat->name, prev)) {
3344  cat = cat->next;
3345  break;
3346  }
3347  }
3348  }
3349  }
3350 
3351  if (cat)
3352  cat = next_available_category(cat);
3353 
3354  config->last_browse = cat;
3355  return (cat) ? cat->name : NULL;
3356 }
struct ast_category * next
Definition: main/config.c:246
struct ast_category * prev
Definition: main/config.c:244
struct ast_category * last_browse
Definition: main/config.c:255
struct ast_category * root
Definition: main/config.c:251
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.

Parameters
configWhich config structure you wish to "browse"
category_nameAn optional category name. Pass NULL to not restrict by category name.
prevA pointer to the starting category structure. Pass NULL to start at the beginning.
filterAn optional comma-separated list of <name_regex>=<value_regex> pairs. Only categories with matching variables will be returned. The special name 'TEMPLATES' can be used with the special values 'include' or 'restrict' to include templates in the result or restrict the result to only templates.
Return values
acategory on success
NULLon failure/no-more-categories

Definition at line 1424 of file main/config.c.

References ast_category::next, and ast_config::root.

Referenced by ast_variable_retrieve_filtered(), handle_updates(), and object_type_loaded_observer().

1426 {
1427  struct ast_category *cat;
1428 
1429  if (!prev) {
1430  prev = config->root;
1431  } else {
1432  prev = prev->next;
1433  }
1434 
1435  cat = next_available_category(prev, category_name, filter);
1436 
1437  return cat;
1438 }
struct ast_category * next
Definition: main/config.c:246
struct ast_category * root
Definition: main/config.c:251
static int filter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:807
struct ast_category* ast_category_delete ( struct ast_config cfg,
struct ast_category cat 
)

Delete a category.

Parameters
cfgwhich config to use
catcategory to delete
Returns
the category after the deleted one which could be NULL.
Note
It is not safe to call ast_category_delete while browsing with ast_category_browse. It is safe with ast_category_browse_filtered.

Definition at line 1567 of file main/config.c.

References ast_config::last, ast_config::last_browse, ast_category::next, ast_category::prev, and ast_config::root.

Referenced by handle_updates(), and object_type_loaded_observer().

1569 {
1570  struct ast_category *prev;
1571 
1572  if (!config || !category) {
1573  return NULL;
1574  }
1575 
1576  if (category->prev) {
1577  category->prev->next = category->next;
1578  } else {
1579  config->root = category->next;
1580  }
1581 
1582  if (category->next) {
1583  category->next->prev = category->prev;
1584  } else {
1585  config->last = category->prev;
1586  }
1587 
1588  prev = category->prev;
1589 
1590  if (config->last_browse == category) {
1591  config->last_browse = prev;
1592  }
1593 
1594  ast_category_destroy(category);
1595 
1596  return prev;
1597 }
struct ast_category * prev
Definition: main/config.c:244
int ast_category_empty ( struct ast_category category)

Removes and destroys all variables in a category.

Parameters
categorycategory to empty
Return values
0if succeeded
-1if category is NULL

Definition at line 1599 of file main/config.c.

References ast_variables_destroy(), ast_category::last, and ast_category::root.

Referenced by handle_updates().

1600 {
1601  if (!category) {
1602  return -1;
1603  }
1604 
1605  ast_variables_destroy(category->root);
1606  category->root = NULL;
1607  category->last = NULL;
1608 
1609  return 0;
1610 }
struct ast_variable * root
Definition: main/config.c:240
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: main/config.c:589
struct ast_variable * last
Definition: main/config.c:242
int ast_category_exist ( const struct ast_config config,
const char *  category_name,
const char *  filter 
)

Check for category duplicates.

Parameters
configwhich config to use
category_namename of the category you're looking for
filteran optional comma-separated list of <name_regex>=<value_regex> pairs. Only categories with matching variables will be returned. The special name 'TEMPLATES' can be used with the special values 'include' or 'restrict' to include templates in the result or restrict the result to only templates.

This will search through the categories within a given config file for a match.

Returns
non-zero if found

Definition at line 1150 of file main/config.c.

References ast_category_get().

1152 {
1153  return !!ast_category_get(config, category_name, filter);
1154 }
struct ast_category * ast_category_get(const struct ast_config *config, const char *category_name, const char *filter)
Retrieve a category if it exists.
Definition: main/config.c:1111
static int filter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:807
struct ast_variable* ast_category_first ( struct ast_category cat)

given a pointer to a category, return the root variable.

This is equivalent to ast_variable_browse(), but more efficient if we already have the struct ast_category * (e.g. from ast_category_get())

return the first var of a category

Definition at line 1246 of file main/config.c.

References ast_category::root.

Referenced by object_type_loaded_observer(), process_text_line(), sorcery_is_criteria_met(), and sorcery_is_explicit_name_met().

1247 {
1248  return (cat) ? cat->root : NULL;
1249 }
struct ast_variable * root
Definition: main/config.c:240
struct ast_category* ast_category_get ( const struct ast_config config,
const char *  category_name,
const char *  filter 
)

Retrieve a category if it exists.

Parameters
configwhich config to use
category_namename of the category you're looking for
filterIf a config contains more than 1 category with the same name, you can specify a filter to narrow the search. The filter is a comma-separated list of <name_regex>=<value_regex> pairs. Only a category with matching variables will be returned. The special name 'TEMPLATES' can be used with the special values 'include' or 'restrict' to include templates in the result or restrict the result to only templates.

This will search through the categories within a given config file for a match.

Return values
pointerto category if found
NULLif not.

Definition at line 1111 of file main/config.c.

Referenced by ast_category_exist(), ast_category_root(), handle_updates(), object_type_loaded_observer(), vm_change_password(), and vm_forwardoptions().

1113 {
1114  return category_get_sep(config, category_name, filter, ',', 1);
1115 }
static int filter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:807
const char* ast_category_get_name ( const struct ast_category category)

Return the name of the category.

Parameters
categorycategory structure
Return values
pointerto category name if found
NULLif not.

Definition at line 1117 of file main/config.c.

Referenced by object_type_loaded_observer(), and sorcery_is_explicit_name_met().

1118 {
1119  return category->name;
1120 }
struct ast_str* ast_category_get_templates ( const struct ast_category category)

Return the template names this category inherits from.

Parameters
categorycategory structure
Returns
an ast_str (which must be freed after use) with a comma separated list of templates names or NULL if there were no templates.

Definition at line 1127 of file main/config.c.

References AST_LIST_EMPTY, AST_LIST_TRAVERSE, ast_str_append(), ast_str_create, and ast_category::next.

1128 {
1129  struct ast_category_template_instance *template;
1130  struct ast_str *str;
1131  int first = 1;
1132 
1133  if (AST_LIST_EMPTY(&category->template_instances)) {
1134  return NULL;
1135  }
1136 
1137  str = ast_str_create(128);
1138  if (!str) {
1139  return NULL;
1140  }
1141 
1142  AST_LIST_TRAVERSE(&category->template_instances, template, next) {
1143  ast_str_append(&str, 0, "%s%s", first ? "" : ",", template->name);
1144  first = 0;
1145  }
1146 
1147  return str;
1148 }
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1139
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:450
Support for dynamic strings.
Definition: strings.h:623
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:491
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
int ast_category_inherit ( struct ast_category existing,
const struct ast_category base 
)

Applies base (template) to category.

Parameters
existingexisting category
basebase category

This function is used to apply a base (template) to an existing category

Return values
0if succeeded
-1if the memory allocation failed

Definition at line 1456 of file main/config.c.

References ast_calloc, AST_LIST_INSERT_TAIL, ast_variable::inherited, ast_variable::next, ast_category::next, and ast_category::root.

Referenced by handle_updates(), and process_text_line().

1457 {
1458  struct ast_variable *var;
1460 
1461  x = ast_calloc(1, sizeof(*x));
1462  if (!x) {
1463  return -1;
1464  }
1465  strcpy(x->name, base->name);
1466  x->inst = base;
1467  AST_LIST_INSERT_TAIL(&new->template_instances, x, next);
1468  for (var = base->root; var; var = var->next) {
1469  struct ast_variable *cloned = variable_clone(var);
1470  if (!cloned) {
1471  return -1;
1472  }
1473  cloned->inherited = 1;
1474  ast_variable_append(new, cloned);
1475  }
1476  return 0;
1477 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
struct ast_variable * root
Definition: main/config.c:240
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:731
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
int ast_category_insert ( struct ast_config config,
struct ast_category cat,
const char *  match 
)

Inserts new category.

Parameters
configwhich config to use
catnewly created category to insert
matchwhich category to insert above

This function is used to insert a new category above another category matching the match parameter.

Return values
0if succeeded
-1if the specified match category wasn't found

Definition at line 1172 of file main/config.c.

References ast_category::next, ast_category::prev, and ast_config::root.

Referenced by handle_updates().

1173 {
1174  struct ast_category *cur_category;
1175 
1176  if (!config || !config->root || !cat || !match) {
1177  return -1;
1178  }
1179 
1180  if (!strcasecmp(config->root->name, match)) {
1181  cat->next = config->root;
1182  cat->prev = NULL;
1183  config->root->prev = cat;
1184  config->root = cat;
1185  return 0;
1186  }
1187 
1188  for (cur_category = config->root->next; cur_category; cur_category = cur_category->next) {
1189  if (!strcasecmp(cur_category->name, match)) {
1190  cat->prev = cur_category->prev;
1191  cat->prev->next = cat;
1192 
1193  cat->next = cur_category;
1194  cur_category->prev = cat;
1195 
1196  return 0;
1197  }
1198  }
1199 
1200  return -1;
1201 }
struct ast_category * next
Definition: main/config.c:246
struct ast_category * prev
Definition: main/config.c:244
struct ast_category * root
Definition: main/config.c:251
int ast_category_is_template ( const struct ast_category category)

Check if category is a template.

Parameters
categorycategory structure
Return values
1if a template.
0if not.

Definition at line 1122 of file main/config.c.

References ast_category::ignored.

1123 {
1124  return category->ignored;
1125 }
static struct ast_category * ast_category_new ( const char *  name,
const char *  in_file,
int  lineno 
)

Create a category.

Parameters
namename of new category
in_filefilename which contained the new config
linenoline number

Definition at line 2788 of file extconf.c.

References ast_calloc, ast_category_new(), ast_copy_string(), and ast_category::file.

Referenced by ast_category_new(), ast_config_copy(), build_cfg(), handle_updates(), and process_text_line().

2789 {
2790  struct ast_category *category;
2791 
2792  if ((category = ast_calloc(1, sizeof(*category))))
2793  ast_copy_string(category->name, name, sizeof(category->name));
2794  category->file = strdup(in_file);
2795  category->lineno = lineno; /* if you don't know the lineno, set it to 999999 or something real big */
2796  return category;
2797 }
char * file
The file name from whence this declaration was read.
Definition: main/config.c:233
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
struct ast_category* ast_category_new_template ( const char *  name,
const char *  in_file,
int  lineno 
)

Create a category making it a template.

Parameters
namename of new template
in_filefilename which contained the new config
linenoline number

Definition at line 1084 of file main/config.c.

Referenced by handle_updates().

1085 {
1086  return new_category(name, in_file, lineno, 1);
1087 }
struct ast_variable* ast_category_root ( struct ast_config config,
char *  cat 
)

returns the root ast_variable of a config

Parameters
configpointer to an ast_config data structure
catname of the category for which you want the root
Returns
the category specified

Definition at line 1251 of file main/config.c.

References ast_category_get(), and ast_category::root.

1252 {
1253  struct ast_category *category = ast_category_get(config, cat, NULL);
1254 
1255  if (category)
1256  return category->root;
1257  return NULL;
1258 }
struct ast_variable * root
Definition: main/config.c:240
struct ast_category * ast_category_get(const struct ast_config *config, const char *category_name, const char *filter)
Retrieve a category if it exists.
Definition: main/config.c:1111
int ast_check_realtime ( const char *  family)

Check if realtime engine is configured for family.

Parameters
familywhich family/config to be checked
Returns
1 if family is configured in realtime and engine exists

Definition at line 3530 of file main/config.c.

References ast_realtime_enabled(), and find_engine().

Referenced by __queues_show(), ast_named_acl_find(), copy_plain_file(), handle_voicemail_show_users(), leave_voicemail(), load_module(), load_realtime_rules(), manager_queues_status(), manager_queues_summary(), rename_file(), and vm_delete().

3531 {
3532  struct ast_config_engine *eng;
3533  if (!ast_realtime_enabled()) {
3534  return 0; /* There are no engines at all so fail early */
3535  }
3536 
3537  eng = find_engine(family, 1, NULL, 0, NULL, 0);
3538  if (eng)
3539  return 1;
3540  return 0;
3541 }
int ast_realtime_enabled(void)
Check if there's any realtime engines loaded.
Definition: main/config.c:3544
Configuration engine structure, used to define realtime drivers.
static struct ast_config_engine * find_engine(const char *family, int priority, char *database, int dbsiz, char *table, int tabsiz)
Find realtime engine for realtime family.
Definition: main/config.c:3209
struct ast_config* ast_config_copy ( const struct ast_config orig)

Copies the contents of one ast_config into another.

Note
This creates a config on the heap. The caller of this must be prepared to free the memory returned.
Parameters
origthe config to copy
Returns
The new config on success, NULL on failure.

Definition at line 3246 of file main/config.c.

References ast_category_append(), ast_category_new(), ast_config_destroy(), ast_config_new(), ast_variables_dup(), ast_category::file, ast_category::last, ast_category::next, ast_category::root, and ast_config::root.

3247 {
3248  struct ast_config *new_config = ast_config_new();
3249  struct ast_category *cat_iter;
3250 
3251  if (!new_config) {
3252  return NULL;
3253  }
3254 
3255  for (cat_iter = old->root; cat_iter; cat_iter = cat_iter->next) {
3256  struct ast_category *new_cat =
3257  ast_category_new(cat_iter->name, cat_iter->file, cat_iter->lineno);
3258  if (!new_cat) {
3259  goto fail;
3260  }
3261  ast_category_append(new_config, new_cat);
3262  if (cat_iter->root) {
3263  new_cat->root = ast_variables_dup(cat_iter->root);
3264  if (!new_cat->root) {
3265  goto fail;
3266  }
3267  new_cat->last = cat_iter->last;
3268  }
3269  }
3270 
3271  return new_config;
3272 
3273 fail:
3274  ast_config_destroy(new_config);
3275  return NULL;
3276 }
struct ast_category * next
Definition: main/config.c:246
char * file
The file name from whence this declaration was read.
Definition: main/config.c:233
void ast_category_append(struct ast_config *config, struct ast_category *category)
Appends a category to a config.
Definition: main/config.c:1156
struct ast_variable * ast_variables_dup(struct ast_variable *var)
Duplicate variable list.
Definition: main/config.c:543
struct ast_variable * root
Definition: main/config.c:240
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
Definition: main/config.c:1612
struct ast_config * ast_config_new(void)
Create a new base configuration structure.
Definition: main/config.c:1479
struct ast_variable * last
Definition: main/config.c:242
struct ast_category * ast_category_new(const char *name, const char *in_file, int lineno)
Create a category.
Definition: main/config.c:1079
static void ast_config_destroy ( struct ast_config cfg)

Destroys a config.

Parameters
cfgpointer to config data structure

Free memory associated with a given config

Definition at line 1289 of file extconf.c.

References ast_config_destroy(), ast_variables_destroy(), ast_config::includes, ast_category::next, ast_category::root, and ast_config::root.

Referenced by __ast_sorcery_apply_config(), __queues_show(), aco_process_config(), advanced_options(), ast_cli_perms_init(), ast_config_copy(), ast_config_destroy(), ast_config_load2(), ast_init_logger_for_socket_console(), ast_load_realtime_multientry_fields(), build_cfg(), conf_exec(), find_load_queue_rt_friendly(), forward_message(), handle_cli_dialplan_save(), init_logger_chain(), load_config(), load_config_force(), load_indications(), load_module(), load_realtime_rules(), make_email_file(), message_range_and_existence_check(), notify_new_message(), object_type_loaded_observer(), parse_config(), pbx_load_users(), private_enum_init(), realtime_sqlite3_multi(), reload(), reload_followme(), reload_queue_rules(), reload_queues(), rtp_reload(), set_config(), vm_change_password(), vm_forwardoptions(), and vm_msg_snapshot_create().

1290 {
1291  struct ast_category *cat, *catn;
1292 
1293  if (!cfg)
1294  return;
1295 
1296  ast_includes_destroy(cfg->includes);
1297 
1298  cat = cfg->root;
1299  while (cat) {
1301  catn = cat;
1302  cat = cat->next;
1303  free(catn);
1304  }
1305  free(cfg);
1306 }
struct ast_category * next
Definition: main/config.c:246
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1262
struct ast_config_include * includes
Definition: main/config.c:258
struct ast_variable * root
Definition: main/config.c:240
struct ast_category * root
Definition: main/config.c:251
int ast_config_engine_deregister ( struct ast_config_engine del)

Deregister config engine.

Return values
0Always

Definition at line 3173 of file main/config.c.

References ast_category::last, lock, and SCOPED_MUTEX.

Referenced by parse_config(), and unload_module().

3174 {
3175  struct ast_config_engine *ptr, *last=NULL;
3176 
3177  SCOPED_MUTEX(lock, &config_lock);
3178 
3179  for (ptr = config_engine_list; ptr; ptr=ptr->next) {
3180  if (ptr == del) {
3181  if (last)
3182  last->next = ptr->next;
3183  else
3184  config_engine_list = ptr->next;
3185  break;
3186  }
3187  last = ptr;
3188  }
3189 
3190  return 0;
3191 }
Configuration engine structure, used to define realtime drivers.
ast_mutex_t lock
#define SCOPED_MUTEX(varname, lock)
scoped lock specialization for mutexes
Definition: lock.h:589
int ast_config_engine_register ( struct ast_config_engine newconfig)

Register config engine.

Return values
1Always

Definition at line 3157 of file main/config.c.

References lock, and SCOPED_MUTEX.

Referenced by load_module().

3158 {
3159  struct ast_config_engine *ptr;
3160 
3161  SCOPED_MUTEX(lock, &config_lock);
3162 
3163  if (!config_engine_list) {
3164  config_engine_list = new;
3165  } else {
3166  for (ptr = config_engine_list; ptr->next; ptr=ptr->next);
3167  ptr->next = new;
3168  }
3169 
3170  return 1;
3171 }
Configuration engine structure, used to define realtime drivers.
ast_mutex_t lock
#define SCOPED_MUTEX(varname, lock)
scoped lock specialization for mutexes
Definition: lock.h:589
struct ast_category * ast_config_get_current_category ( const struct ast_config cfg)

Retrieve the current category name being built.

API for backend configuration engines while building a configuration set.

Definition at line 2781 of file extconf.c.

Referenced by config_text_file_load().

2782 {
2783  return cfg->current;
2784 }
int ast_config_hook_register ( const char *  name,
const char *  filename,
const char *  module,
enum config_hook_flags  flags,
config_hook_cb  hook 
)

Register a config hook for a particular file and module.

Parameters
nameThe name of the hook you are registering.
filenameThe file whose config you wish to hook into.
moduleThe module that is reloading the config. This can be useful if multiple modules may possibly reload the same file, but you are only interested when a specific module reloads the file
flagsFlags that affect the way hooks work.
hookThe callback to be called when config is loaded. return 0 Success return -1 Unsuccess, also known as UTTER AND COMPLETE FAILURE

Definition at line 4302 of file main/config.c.

References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ao2_link, ao2_ref, and ast_strdup.

4307 {
4308  struct cfg_hook *hook;
4309  if (!cfg_hooks) {
4311  hook_hash, NULL, hook_cmp);
4312  if (!cfg_hooks) {
4313  return -1;
4314  }
4315  }
4316 
4317  if (!(hook = ao2_alloc(sizeof(*hook), hook_destroy))) {
4318  return -1;
4319  }
4320 
4321  hook->hook_cb = hook_cb;
4322  hook->filename = ast_strdup(filename);
4323  hook->name = ast_strdup(name);
4324  hook->module = ast_strdup(module);
4325 
4326  ao2_link(cfg_hooks, hook);
4327  ao2_ref(hook, -1);
4328  return 0;
4329 }
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#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.
Definition: astobj2.h:1303
#define ao2_link(container, obj)
Add an object to a container.
Definition: astobj2.h:1532
void ast_config_hook_unregister ( const char *  name)

Unregister a config hook.

Parameters
nameThe name of the hook to unregister

Definition at line 4274 of file main/config.c.

References ast_strdupa, OBJ_NODATA, OBJ_POINTER, and OBJ_UNLINK.

4275 {
4276  struct cfg_hook tmp;
4277 
4278  tmp.name = ast_strdupa(name);
4279 
4280  ao2_find(cfg_hooks, &tmp, OBJ_POINTER | OBJ_UNLINK | OBJ_NODATA);
4281 }
#define OBJ_POINTER
Definition: astobj2.h:1150
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
struct ast_config* ast_config_load2 ( const char *  filename,
const char *  who_asked,
struct ast_flags  flags 
)

Load a config file.

Parameters
filenamepath of file to open. If no preceding '/' character, path is considered relative to AST_CONFIG_DIR
who_askedThe module which is making this request.
flagsOptional flags: CONFIG_FLAG_WITHCOMMENTS - load the file with comments intact; CONFIG_FLAG_FILEUNCHANGED - check the file mtime and return CONFIG_STATUS_FILEUNCHANGED if the mtime is the same; or CONFIG_FLAG_NOCACHE - don't cache file mtime (main purpose of this option is to save memory on temporary files).

Create a config structure from a given configuration file.

Returns
an ast_config data structure on success
Return values
NULLon error

Definition at line 3321 of file main/config.c.

References ast_config_destroy(), and ast_config_new().

Referenced by __ast_sorcery_apply_config(), ast_cli_perms_init(), ast_init_logger_for_socket_console(), init_logger_chain(), load_indications(), object_type_loaded_observer(), private_enum_init(), rtp_reload(), and set_config().

3322 {
3323  struct ast_config *cfg;
3324  struct ast_config *result;
3325 
3326  cfg = ast_config_new();
3327  if (!cfg)
3328  return NULL;
3329 
3330  result = ast_config_internal_load(filename, cfg, flags, "", who_asked);
3331  if (!result || result == CONFIG_STATUS_FILEUNCHANGED || result == CONFIG_STATUS_FILEINVALID)
3332  ast_config_destroy(cfg);
3333 
3334  return result;
3335 }
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
Definition: main/config.c:1612
struct ast_config * ast_config_new(void)
Create a new base configuration structure.
Definition: main/config.c:1479
const char* ast_config_option ( struct ast_config cfg,
const char *  cat,
const char *  var 
)

Retrieve a configuration variable within the configuration set.

Retrieves the named variable var within category cat of configuration set cfg. If not found, attempts to retrieve the named variable var from within category general.

Returns
Value of var, or NULL if not found.

Definition at line 773 of file main/config.c.

Referenced by pbx_load_users().

774 {
775  const char *tmp;
776  tmp = ast_variable_retrieve(cfg, cat, var);
777  if (!tmp) {
778  tmp = ast_variable_retrieve(cfg, "general", var);
779  }
780  return tmp;
781 }
void ast_config_set_current_category ( struct ast_config cfg,
const struct ast_category cat 
)

Set the category within the configuration as being current.

API for backend configuration engines while building a configuration set.

Definition at line 3362 of file extconf.c.

Referenced by process_text_line().

3363 {
3364  /* cast below is just to silence compiler warning about dropping "const" */
3365  cfg->current = (struct ast_category *) cat;
3366 }
void ast_config_sort_categories ( struct ast_config config,
int  descending,
int(*)(struct ast_category *p, struct ast_category *q)  comparator 
)

Sorts categories in a config in the order of a numerical value contained within them.

Parameters
configThe config structure you wish to sort
comparatorvariable Which numerical value you wish to sort by
descendingIf true, we sort highest to lowest instead of lowest to highest

This function will assume a value of 0 for any non-numerical strings and NULL fields.

Definition at line 1260 of file main/config.c.

References ast_category::next, and ast_config::root.

1262 {
1263  /*
1264  * The contents of this function are adapted from
1265  * an example of linked list merge sorting
1266  * copyright 2001 Simon Tatham.
1267  *
1268  * Permission is hereby granted, free of charge, to any person
1269  * obtaining a copy of this software and associated documentation
1270  * files (the "Software"), to deal in the Software without
1271  * restriction, including without limitation the rights to use,
1272  * copy, modify, merge, publish, distribute, sublicense, and/or
1273  * sell copies of the Software, and to permit persons to whom the
1274  * Software is furnished to do so, subject to the following
1275  * conditions:
1276  *
1277  * The above copyright notice and this permission notice shall be
1278  * included in all copies or substantial portions of the Software.
1279  *
1280  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1281  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
1282  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1283  * NONINFRINGEMENT. IN NO EVENT SHALL SIMON TATHAM BE LIABLE FOR
1284  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
1285  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1286  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1287  * SOFTWARE.
1288  */
1289 
1290  int insize = 1;
1291  struct ast_category *p, *q, *e, *tail;
1292  int nmerges, psize, qsize, i;
1293 
1294  /* If the descending flag was sent, we'll apply inversion to the comparison function's return. */
1295  if (descending) {
1296  descending = -1;
1297  } else {
1298  descending = 1;
1299  }
1300 
1301  if (!config->root) {
1302  return;
1303  }
1304 
1305  while (1) {
1306  p = config->root;
1307  config->root = NULL;
1308  tail = NULL;
1309 
1310  nmerges = 0; /* count number of merges we do in this pass */
1311 
1312  while (p) {
1313  nmerges++; /* there exists a merge to be done */
1314 
1315  /* step `insize' places along from p */
1316  q = p;
1317  psize = 0;
1318  for (i = 0; i < insize; i++) {
1319  psize++;
1320  q = q->next;
1321  if (!q) {
1322  break;
1323  }
1324  }
1325 
1326  /* if q hasn't fallen off end, we have two lists to merge */
1327  qsize = insize;
1328 
1329  /* now we have two lists; merge them */
1330  while (psize > 0 || (qsize > 0 && q)) {
1331  /* decide whether next element of merge comes from p or q */
1332  if (psize == 0) {
1333  /* p is empty; e must come from q. */
1334  e = q;
1335  q = q->next;
1336  qsize--;
1337  } else if (qsize == 0 || !q) {
1338  /* q is empty; e must come from p. */
1339  e = p; p = p->next; psize--;
1340  } else if ((comparator(p,q) * descending) <= 0) {
1341  /* First element of p is lower (or same) e must come from p. */
1342  e = p;
1343  p = p->next;
1344  psize--;
1345  } else {
1346  /* First element of q is lower; e must come from q. */
1347  e = q;
1348  q = q->next;
1349  qsize--;
1350  }
1351 
1352  /* add the next element to the merged list */
1353  if (tail) {
1354  tail->next = e;
1355  } else {
1356  config->root = e;
1357  }
1358  tail = e;
1359  }
1360 
1361  /* now p has stepped `insize' places along, and q has too */
1362  p = q;
1363  }
1364 
1365  tail->next = NULL;
1366 
1367  /* If we have done only one merge, we're finished. */
1368  if (nmerges <= 1) { /* allow for nmerges==0, the empty list case */
1369  return;
1370  }
1371 
1372  /* Otherwise repeat, merging lists twice the size */
1373  insize *= 2;
1374  }
1375 
1376 }
struct ast_category * next
Definition: main/config.c:246
struct ast_category * root
Definition: main/config.c:251
int ast_config_text_file_save ( const char *  filename,
const struct ast_config cfg,
const char *  generator 
)

Save a config text file preserving the pre 13.2 behavior.

Parameters
filenameFilename
cfgast_config
generatorgenerator
Return values
0on success.
-1on failure.

Definition at line 2701 of file main/config.c.

References ast_config_text_file_save2(), and CONFIG_SAVE_FLAG_PRESERVE_EFFECTIVE_CONTEXT.

Referenced by vm_change_password(), and vm_forwardoptions().

2702 {
2703  return ast_config_text_file_save2(configfile, cfg, generator, CONFIG_SAVE_FLAG_PRESERVE_EFFECTIVE_CONTEXT);
2704 }
int ast_config_text_file_save2(const char *configfile, const struct ast_config *cfg, const char *generator, uint32_t flags)
Save a config text file.
Definition: main/config.c:2725
int ast_config_text_file_save2 ( const char *  filename,
const struct ast_config cfg,
const char *  generator,
uint32_t  flags 
)

Save a config text file.

Since
13.2.0
Parameters
filenameFilename
cfgast_config
generatorgenerator
flagsList of config_save_flags
Return values
0on success.
-1on failure.

Definition at line 2725 of file main/config.c.

References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ao2_ref, ast_debug, ast_escape_semicolons(), AST_LIST_EMPTY, AST_LIST_LAST, AST_LIST_TRAVERSE, ast_variable::blanklines, ast_comment::cmt, CONFIG_SAVE_FLAG_PRESERVE_EFFECTIVE_CONTEXT, ast_config_include::exec, ast_config_include::exec_file, ast_variable::file, ast_category::file, ast_category::ignored, ast_config_include::include_location_file, ast_config_include::include_location_lineno, ast_config_include::included_file, ast_config::includes, ast_variable::inherited, ast_variable::name, ast_variable::next, ast_category::next, ast_config_include::next, ast_variable::object, ast_config_include::output, ast_category::root, ast_config::root, ast_variable::trailing, ast_category::trailing, and ast_variable::value.

Referenced by ast_config_text_file_save().

2726 {
2727  FILE *f;
2728  char fn[PATH_MAX];
2729  struct ast_variable *var;
2730  struct ast_category *cat;
2731  struct ast_comment *cmt;
2732  struct ast_config_include *incl;
2733  int blanklines = 0;
2734  struct ao2_container *fileset;
2735  struct inclfile *fi;
2736 
2738  hash_string, NULL, hashtab_compare_strings);
2739  if (!fileset) {
2740  /* Container creation failed. */
2741  return -1;
2742  }
2743 
2744  /* Check all the files for write access before attempting to modify any of them */
2745  for (incl = cfg->includes; incl; incl = incl->next) {
2746  /* reset all the output flags in case this isn't our first time saving this data */
2747  incl->output = 0;
2748 
2749  if (!incl->exec) {
2750  /* now make sure we have write access to the include file or its parent directory */
2751  make_fn(fn, sizeof(fn), incl->included_file, configfile);
2752  /* If the file itself doesn't exist, make sure we have write access to the directory */
2753  if (!is_writable(fn)) {
2754  return -1;
2755  }
2756  }
2757  }
2758 
2759  /* now make sure we have write access to the main config file or its parent directory */
2760  make_fn(fn, sizeof(fn), 0, configfile);
2761  if (!is_writable(fn)) {
2762  return -1;
2763  }
2764 
2765  /* Now that we know we have write access to all files, it's safe to start truncating them */
2766 
2767  /* go thru all the inclusions and make sure all the files involved (configfile plus all its inclusions)
2768  are all truncated to zero bytes and have that nice header*/
2769  for (incl = cfg->includes; incl; incl = incl->next) {
2770  if (!incl->exec) { /* leave the execs alone -- we'll write out the #exec directives, but won't zero out the include files or exec files*/
2771  /* normally, fn is just set to incl->included_file, prepended with config dir if relative */
2772  fi = set_fn(fn, sizeof(fn), incl->included_file, configfile, fileset);
2773  f = fopen(fn, "w");
2774  if (f) {
2775  gen_header(f, configfile, fn, generator);
2776  fclose(f); /* this should zero out the file */
2777  } else {
2778  ast_log(LOG_ERROR, "Unable to write %s (%s)\n", fn, strerror(errno));
2779  }
2780  if (fi) {
2781  ao2_ref(fi, -1);
2782  }
2783  }
2784  }
2785 
2786  /* just set fn to absolute ver of configfile */
2787  fi = set_fn(fn, sizeof(fn), 0, configfile, fileset);
2788  if (
2789 #ifdef __CYGWIN__
2790  (f = fopen(fn, "w+"))
2791 #else
2792  (f = fopen(fn, "w"))
2793 #endif
2794  ) {
2795  ast_verb(2, "Saving '%s'\n", fn);
2796  gen_header(f, configfile, fn, generator);
2797  cat = cfg->root;
2798  fclose(f);
2799  if (fi) {
2800  ao2_ref(fi, -1);
2801  }
2802 
2803  /* from here out, we open each involved file and concat the stuff we need to add to the end and immediately close... */
2804  /* since each var, cat, and associated comments can come from any file, we have to be
2805  mobile, and open each file, print, and close it on an entry-by-entry basis */
2806 
2807  while (cat) {
2808  fi = set_fn(fn, sizeof(fn), cat->file, configfile, fileset);
2809  f = fopen(fn, "a");
2810  if (!f) {
2811  ast_log(LOG_ERROR, "Unable to write %s (%s)\n", fn, strerror(errno));
2812  if (fi) {
2813  ao2_ref(fi, -1);
2814  }
2815  ao2_ref(fileset, -1);
2816  return -1;
2817  }
2818 
2819  /* dump any includes that happen before this category header */
2820  for (incl=cfg->includes; incl; incl = incl->next) {
2821  if (strcmp(incl->include_location_file, cat->file) == 0){
2822  if (cat->lineno > incl->include_location_lineno && !incl->output) {
2823  if (incl->exec)
2824  fprintf(f,"#exec \"%s\"\n", incl->exec_file);
2825  else
2826  fprintf(f,"#include \"%s\"\n", incl->included_file);
2827  incl->output = 1;
2828  }
2829  }
2830  }
2831 
2832  insert_leading_blank_lines(f, fi, cat->precomments, cat->lineno);
2833  /* Dump section with any appropriate comment */
2834  for (cmt = cat->precomments; cmt; cmt=cmt->next) {
2835  char *cmtp = cmt->cmt;
2836  while (cmtp && *cmtp == ';' && *(cmtp+1) == '!') {
2837  char *cmtp2 = strchr(cmtp+1, '\n');
2838  if (cmtp2)
2839  cmtp = cmtp2+1;
2840  else cmtp = 0;
2841  }
2842  if (cmtp)
2843  fprintf(f,"%s", cmtp);
2844  }
2845  fprintf(f, "[%s]", cat->name);
2846  if (cat->ignored || !AST_LIST_EMPTY(&cat->template_instances)) {
2847  fprintf(f, "(");
2848  if (cat->ignored) {
2849  fprintf(f, "!");
2850  }
2851  if (cat->ignored && !AST_LIST_EMPTY(&cat->template_instances)) {
2852  fprintf(f, ",");
2853  }
2854  if (!AST_LIST_EMPTY(&cat->template_instances)) {
2856  AST_LIST_TRAVERSE(&cat->template_instances, x, next) {
2857  fprintf(f,"%s",x->name);
2858  if (x != AST_LIST_LAST(&cat->template_instances))
2859  fprintf(f,",");
2860  }
2861  }
2862  fprintf(f, ")");
2863  }
2864  for(cmt = cat->sameline; cmt; cmt=cmt->next)
2865  {
2866  fprintf(f,"%s", cmt->cmt);
2867  }
2868  if (!cat->sameline)
2869  fprintf(f,"\n");
2870  for (cmt = cat->trailing; cmt; cmt=cmt->next) {
2871  if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
2872  fprintf(f,"%s", cmt->cmt);
2873  }
2874  fclose(f);
2875  if (fi) {
2876  ao2_ref(fi, -1);
2877  }
2878 
2879  var = cat->root;
2880  while (var) {
2882  int found = 0;
2883 
2884  AST_LIST_TRAVERSE(&cat->template_instances, x, next) {
2885  struct ast_variable *v;
2886  for (v = x->inst->root; v; v = v->next) {
2887 
2889  if (!strcasecmp(var->name, v->name) && !strcmp(var->value, v->value)) {
2890  found = 1;
2891  break;
2892  }
2893  } else {
2894  if (var->inherited) {
2895  found = 1;
2896  break;
2897  } else {
2898  if (!strcasecmp(var->name, v->name) && !strcmp(var->value, v->value)) {
2899  found = 1;
2900  break;
2901  }
2902  }
2903  }
2904  }
2905  if (found) {
2906  break;
2907  }
2908  }
2909  if (found) {
2910  var = var->next;
2911  continue;
2912  }
2913  fi = set_fn(fn, sizeof(fn), var->file, configfile, fileset);
2914  f = fopen(fn, "a");
2915  if (!f) {
2916  ast_debug(1, "Unable to open for writing: %s\n", fn);
2917  ast_verb(2, "Unable to write %s (%s)\n", fn, strerror(errno));
2918  if (fi) {
2919  ao2_ref(fi, -1);
2920  }
2921  ao2_ref(fileset, -1);
2922  return -1;
2923  }
2924 
2925  /* dump any includes that happen before this category header */
2926  for (incl=cfg->includes; incl; incl = incl->next) {
2927  if (strcmp(incl->include_location_file, var->file) == 0){
2928  if (var->lineno > incl->include_location_lineno && !incl->output) {
2929  if (incl->exec)
2930  fprintf(f,"#exec \"%s\"\n", incl->exec_file);
2931  else
2932  fprintf(f,"#include \"%s\"\n", incl->included_file);
2933  incl->output = 1;
2934  }
2935  }
2936  }
2937 
2938  insert_leading_blank_lines(f, fi, var->precomments, var->lineno);
2939  for (cmt = var->precomments; cmt; cmt=cmt->next) {
2940  if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
2941  fprintf(f,"%s", cmt->cmt);
2942  }
2943 
2944  { /* Block for 'escaped' scope */
2945  int escaped_len = 2 * strlen(var->value) + 1;
2946  char escaped[escaped_len];
2947 
2948  ast_escape_semicolons(var->value, escaped, escaped_len);
2949 
2950  if (var->sameline) {
2951  fprintf(f, "%s %s %s %s", var->name, (var->object ? "=>" : "="),
2952  escaped, var->sameline->cmt);
2953  } else {
2954  fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="),
2955  escaped);
2956  }
2957  }
2958 
2959  for (cmt = var->trailing; cmt; cmt=cmt->next) {
2960  if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
2961  fprintf(f,"%s", cmt->cmt);
2962  }
2963  if (var->blanklines) {
2964  blanklines = var->blanklines;
2965  while (blanklines--)
2966  fprintf(f, "\n");
2967  }
2968 
2969  fclose(f);
2970  if (fi) {
2971  ao2_ref(fi, -1);
2972  }
2973 
2974  var = var->next;
2975  }
2976  cat = cat->next;
2977  }
2978  ast_verb(2, "Saving '%s': saved\n", fn);
2979  } else {
2980  ast_debug(1, "Unable to open for writing: %s\n", fn);
2981  ast_verb(2, "Unable to write '%s' (%s)\n", fn, strerror(errno));
2982  if (fi) {
2983  ao2_ref(fi, -1);
2984  }
2985  ao2_ref(fileset, -1);
2986  return -1;
2987  }
2988 
2989  /* Now, for files with trailing #include/#exec statements,
2990  we have to make sure every entry is output */
2991  for (incl=cfg->includes; incl; incl = incl->next) {
2992  if (!incl->output) {
2993  /* open the respective file */
2994  fi = set_fn(fn, sizeof(fn), incl->include_location_file, configfile, fileset);
2995  f = fopen(fn, "a");
2996  if (!f) {
2997  ast_debug(1, "Unable to open for writing: %s\n", fn);
2998  ast_verb(2, "Unable to write %s (%s)\n", fn, strerror(errno));
2999  if (fi) {
3000  ao2_ref(fi, -1);
3001  }
3002  ao2_ref(fileset, -1);
3003  return -1;
3004  }
3005 
3006  /* output the respective include */
3007  if (incl->exec)
3008  fprintf(f,"#exec \"%s\"\n", incl->exec_file);
3009  else
3010  fprintf(f,"#include \"%s\"\n", incl->included_file);
3011  fclose(f);
3012  incl->output = 1;
3013  if (fi) {
3014  ao2_ref(fi, -1);
3015  }
3016  }
3017  }
3018  ao2_ref(fileset, -1); /* this should destroy the hash container */
3019 
3020  /* pass new configuration to any config hooks */
3021  config_hook_exec(configfile, generator, cfg);
3022 
3023  return 0;
3024 }
struct ast_variable * next
struct ast_category * next
Definition: main/config.c:246
Structure to keep comments for rewriting configuration files.
Definition: main/config.c:84
char * file
The file name from whence this declaration was read.
Definition: main/config.c:233
char * include_location_file
file name in which the include occurs
Definition: main/config.c:266
struct ast_config_include * includes
Definition: main/config.c:258
char cmt[0]
Definition: main/config.c:87
Structure for variables, used for configurations and for channel variables.
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:450
char * ast_escape_semicolons(const char *string, char *outbuf, int buflen)
Escape semicolons found in a string.
Definition: utils.c:811
char * exec_file
if it's an exec, you'll have both the /var/tmp to read, and the original script
Definition: main/config.c:273
struct ast_comment * trailing
struct ast_comment * trailing
Definition: main/config.c:238
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
char * included_file
file name included
Definition: main/config.c:278
#define ast_debug(level,...)
Log a DEBUG message.
struct ast_variable * root
Definition: main/config.c:240
#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.
Definition: astobj2.h:1303
#define AST_LIST_LAST(head)
Returns the last entry contained in a list.
Definition: linkedlists.h:429
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:491
struct ast_config_include * next
Definition: main/config.c:282
Generic container type.
struct ast_category * root
Definition: main/config.c:251
int ast_destroy_realtime ( const char *  family,
const char *  keyfield,
const char *  lookup,
  ... 
)

Destroy realtime configuration.

Parameters
familywhich family/config to be destroyed
keyfieldwhich field to use as the key
lookupwhich value to look for in the key field to match the entry.

This function is used to destroy an entry in realtime configuration space. Additional params are used as keys.

Returns
Number of rows affected, or -1 on error.
Note
You should use the constant SENTINEL to terminate arguments, in order to preserve cross-platform compatibility.

Definition at line 3776 of file main/config.c.

References ast_destroy_realtime_fields(), ast_variables_destroy(), and RAII_VAR.

Referenced by leave_voicemail(), and vm_delete().

3777 {
3778  RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
3779  int res = 0;
3780  va_list ap;
3781 
3782  va_start(ap, lookup);
3783  if (realtime_arguments_to_fields(ap, &fields)) {
3784  res = -1;
3785  }
3786  va_end(ap);
3787 
3788  if (res) {
3789  return -1;
3790  }
3791 
3792  return ast_destroy_realtime_fields(family, keyfield, lookup, fields);
3793 }
int ast_destroy_realtime_fields(const char *family, const char *keyfield, const char *lookup, const struct ast_variable *fields)
Destroy realtime configuration.
Definition: main/config.c:3756
Structure for variables, used for configurations and for channel variables.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: main/config.c:589
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941
int ast_destroy_realtime_fields ( const char *  family,
const char *  keyfield,
const char *  lookup,
const struct ast_variable fields 
)

Destroy realtime configuration.

Parameters
familywhich family/config to be destroyed
keyfieldwhich field to use as the key
lookupwhich value to look for in the key field to match the entry.
fieldsfields themselves

This function is used to destroy an entry in realtime configuration space. Additional params are used as keys.

Returns
Number of rows affected, or -1 on error.

Definition at line 3756 of file main/config.c.

References find_engine().

Referenced by ast_destroy_realtime().

3757 {
3758  struct ast_config_engine *eng;
3759  int res = -1, i;
3760  char db[256];
3761  char table[256];
3762 
3763  for (i = 1; ; i++) {
3764  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3765  if (eng->destroy_func && ((res = eng->destroy_func(db, table, keyfield, lookup, fields)) >= 0)) {
3766  break;
3767  }
3768  } else {
3769  break;
3770  }
3771  }
3772 
3773  return res;
3774 }
Configuration engine structure, used to define realtime drivers.
static struct ast_config_engine * find_engine(const char *family, int priority, char *database, int dbsiz, char *table, int tabsiz)
Find realtime engine for realtime family.
Definition: main/config.c:3209
struct ast_variable* ast_load_realtime_fields ( const char *  family,
const struct ast_variable fields 
)

Retrieve realtime configuration.

Parameters
familywhich family/config to lookup
fieldswhich fields to lookup

This will use builtin configuration backends to look up a particular entity in realtime and return a variable list of its parameters.

Note
Unlike the variables in ast_config, the resulting list of variables MUST be freed with ast_variables_destroy() as there is no container.
The difference between these two calls is that ast_load_realtime excludes fields whose values are NULL, while ast_load_realtime_all loads all columns.
You should use the constant SENTINEL to terminate arguments, in order to preserve cross-platform compatibility.

Definition at line 3471 of file main/config.c.

References ast_variable::next, ast_category::next, ast_category::prev, and ast_variable::value.

3472 {
3473  struct ast_variable *res;
3474  struct ast_variable *cur;
3475  struct ast_variable **prev;
3476 
3477  res = ast_load_realtime_all_fields(family, fields);
3478 
3479  /* Filter the list. */
3480  prev = &res;
3481  cur = res;
3482  while (cur) {
3483  if (ast_strlen_zero(cur->value)) {
3484  /* Eliminate empty entries */
3485  struct ast_variable *next;
3486 
3487  next = cur->next;
3488  *prev = next;
3489  ast_variable_destroy(cur);
3490  cur = next;
3491  } else {
3492  /* Make blank entries empty and keep them. */
3493  if (cur->value[0] == ' ' && cur->value[1] == '\0') {
3494  char *vptr = (char *) cur->value;
3495 
3496  vptr[0] = '\0';
3497  }
3498 
3499  prev = &cur->next;
3500  cur = cur->next;
3501  }
3502  }
3503  return res;
3504 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
struct ast_config* ast_load_realtime_multientry ( const char *  family,
  ... 
)

Retrieve realtime configuration.

Parameters
familywhich family/config to lookup

This will use builtin configuration backends to look up a particular entity in realtime and return a variable list of its parameters. Unlike the ast_load_realtime, this function can return more than one entry and is thus stored inside a traditional ast_config structure rather than just returning a linked list of variables.

Returns
An ast_config with one or more results
Return values
NULLError or no results returned
Note
You should use the constant SENTINEL to terminate arguments, in order to preserve cross-platform compatibility.

Definition at line 3622 of file main/config.c.

References ast_load_realtime_multientry_fields(), ast_variables_destroy(), and RAII_VAR.

Referenced by __queues_show(), conf_exec(), find_load_queue_rt_friendly(), load_module(), and load_realtime_rules().

3623 {
3624  RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
3625  va_list ap;
3626 
3627  va_start(ap, family);
3628  realtime_arguments_to_fields(ap, &fields);
3629  va_end(ap);
3630 
3631  if (!fields) {
3632  return NULL;
3633  }
3634 
3635  return ast_load_realtime_multientry_fields(family, fields);
3636 }
Structure for variables, used for configurations and for channel variables.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: main/config.c:589
struct ast_config * ast_load_realtime_multientry_fields(const char *family, const struct ast_variable *fields)
Retrieve realtime configuration.
Definition: main/config.c:3596
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941
struct ast_config* ast_load_realtime_multientry_fields ( const char *  family,
const struct ast_variable fields 
)

Retrieve realtime configuration.

Parameters
familywhich family/config to lookup
fieldslist of fields

This will use builtin configuration backends to look up a particular entity in realtime and return a variable list of its parameters. Unlike the ast_load_realtime, this function can return more than one entry and is thus stored inside a traditional ast_config structure rather than just returning a linked list of variables.

Returns
An ast_config with one or more results
Return values
NULLError or no results returned

Definition at line 3596 of file main/config.c.

References ast_config_destroy(), find_engine(), and ast_config::root.

Referenced by ast_load_realtime_multientry().

3597 {
3598  struct ast_config_engine *eng;
3599  char db[256];
3600  char table[256];
3601  struct ast_config *res = NULL;
3602  int i;
3603 
3604  for (i = 1; ; i++) {
3605  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3606  if (eng->realtime_multi_func && (res = eng->realtime_multi_func(db, table, fields))) {
3607  /* If we were returned an empty cfg, destroy it and return NULL */
3608  if (!res->root) {
3609  ast_config_destroy(res);
3610  res = NULL;
3611  }
3612  break;
3613  }
3614  } else {
3615  break;
3616  }
3617  }
3618 
3619  return res;
3620 }
Configuration engine structure, used to define realtime drivers.
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
Definition: main/config.c:1612
static struct ast_config_engine * find_engine(const char *family, int priority, char *database, int dbsiz, char *table, int tabsiz)
Find realtime engine for realtime family.
Definition: main/config.c:3209
struct ast_category * root
Definition: main/config.c:251
int ast_parse_arg ( const char *  arg,
enum ast_parse_flags  flags,
void *  p_result,
  ... 
)

The argument parsing routine.

Parameters
argthe string to parse. It is not modified.
flagscombination of ast_parse_flags to specify the return type and additional checks.
p_resultpointer to the result. NULL is valid here, and can be used to perform only the validity checks.
...extra arguments are required according to flags.
Return values
0in case of success, != 0 otherwise.
resultreturns the parsed value in case of success, the default value in case of error, or it is left unchanged in case of error and no default specified. Note that in certain cases (e.g. sockaddr_in, with multi-field return values) some of the fields in result may be changed even if an error occurs.

Examples of use: ast_parse_arg("223", PARSE_INT32|PARSE_IN_RANGE, &a, -1000, 1000); returns 0, a = 223 ast_parse_arg("22345", PARSE_INT32|PARSE_IN_RANGE|PARSE_DEFAULT, &a, 9999, 10, 100); returns 1, a = 9999 ast_parse_arg("22345ssf", PARSE_UINT32|PARSE_IN_RANGE, &b, 10, 100); returns 1, b unchanged ast_parse_arg("12", PARSE_UINT32|PARSE_IN_RANGE|PARSE_RANGE_DEFAULTS, &a, 1, 10); returns 1, a = 10 ast_parse_arg("223", PARSE_TIMELEN|PARSE_IN_RANGE, &a, TIMELEN_SECONDS, -1000, 1000); returns 0, a = 1000 ast_parse_arg("223", PARSE_TIMELEN|PARSE_IN_RANGE, &a, TIMELEN_SECONDS, -1000, 250000); returns 0, a = 223000 ast_parse_arg("223", PARSE_TIMELEN|PARSE_IN_RANGE|PARSE_DEFAULT, &a, TIMELEN_SECONDS, 9999, -1000, 250000); returns 0, a = 9999 ast_parse_arg("www.foo.biz:44", PARSE_INADDR, &sa); returns 0, sa contains address and port ast_parse_arg("www.foo.biz", PARSE_INADDR|PARSE_PORT_REQUIRE, &sa); returns 1 because port is missing, sa contains address

The argument parsing routine.

Examples:
app_skel.c.

Definition at line 3827 of file main/config.c.

References ast_app_parse_timelen(), ast_debug, ast_inet_ntoa(), ast_skip_blanks(), ast_sockaddr_parse(), ast_sockaddr_resolve_first_af(), ast_sockaddr_stringify(), ast_sockaddr_to_sin, and ast_strdupa.

Referenced by ast_tls_read_conf(), build_peer(), double_handler_fn(), int_handler_fn(), new_realtime_sqlite3_db(), realtime_peer(), rtp_reload(), set_config(), sockaddr_handler_fn(), timelen_handler_fn(), and uint_handler_fn().

3829 {
3830  va_list ap;
3831  int error = 0;
3832 
3833  va_start(ap, p_result);
3834  switch (flags & PARSE_TYPE) {
3835  case PARSE_INT32:
3836  {
3837  long int x = 0;
3838  int32_t *result = p_result;
3839  int32_t def = result ? *result : 0, high = INT32_MAX, low = INT32_MIN;
3840  char *endptr = NULL;
3841 
3842  /* optional arguments: default value and/or (low, high) */
3843  if (flags & PARSE_DEFAULT) {
3844  def = va_arg(ap, int32_t);
3845  }
3846  if (flags & (PARSE_IN_RANGE | PARSE_OUT_RANGE)) {
3847  low = va_arg(ap, int32_t);
3848  high = va_arg(ap, int32_t);
3849  }
3850  if (ast_strlen_zero(arg)) {
3851  error = 1;
3852  goto int32_done;
3853  }
3854  errno = 0;
3855  x = strtol(arg, &endptr, 0);
3856  if (*endptr || errno || x < INT32_MIN || x > INT32_MAX) {
3857  /* Parse error, or type out of int32_t bounds */
3858  error = 1;
3859  goto int32_done;
3860  }
3861  error = (x < low) || (x > high);
3862  if (flags & PARSE_RANGE_DEFAULTS) {
3863  if (x < low) {
3864  def = low;
3865  } else if (x > high) {
3866  def = high;
3867  }
3868  }
3869  if (flags & PARSE_OUT_RANGE) {
3870  error = !error;
3871  }
3872 int32_done:
3873  if (result) {
3874  *result = error ? def : x;
3875  }
3876 
3877  ast_debug(3, "extract int from [%s] in [%d, %d] gives [%ld](%d)\n",
3878  arg, low, high, result ? *result : x, error);
3879  break;
3880  }
3881 
3882  case PARSE_UINT32:
3883  {
3884  unsigned long int x = 0;
3885  uint32_t *result = p_result;
3886  uint32_t def = result ? *result : 0, low = 0, high = UINT32_MAX;
3887  char *endptr = NULL;
3888 
3889  /* optional argument: first default value, then range */
3890  if (flags & PARSE_DEFAULT) {
3891  def = va_arg(ap, uint32_t);
3892  }
3893  if (flags & (PARSE_IN_RANGE|PARSE_OUT_RANGE)) {
3894  /* range requested, update bounds */
3895  low = va_arg(ap, uint32_t);
3896  high = va_arg(ap, uint32_t);
3897  }
3898 
3899  if (ast_strlen_zero(arg)) {
3900  error = 1;
3901  goto uint32_done;
3902  }
3903  /* strtoul will happily and silently negate negative numbers */
3904  arg = ast_skip_blanks(arg);
3905  if (*arg == '-') {
3906  error = 1;
3907  goto uint32_done;
3908  }
3909  errno = 0;
3910  x = strtoul(arg, &endptr, 0);
3911  if (*endptr || errno || x > UINT32_MAX) {
3912  error = 1;
3913  goto uint32_done;
3914  }
3915  error = (x < low) || (x > high);
3916  if (flags & PARSE_RANGE_DEFAULTS) {
3917  if (x < low) {
3918  def = low;
3919  } else if (x > high) {
3920  def = high;
3921  }
3922  }
3923  if (flags & PARSE_OUT_RANGE) {
3924  error = !error;
3925  }
3926 uint32_done:
3927  if (result) {
3928  *result = error ? def : x;
3929  }
3930  ast_debug(3, "extract uint from [%s] in [%u, %u] gives [%lu](%d)\n",
3931  arg, low, high, result ? *result : x, error);
3932  break;
3933  }
3934 
3935  case PARSE_TIMELEN:
3936  {
3937  int x = 0;
3938  int *result = p_result;
3939  int def = result ? *result : 0;
3940  int high = INT_MAX;
3941  int low = INT_MIN;
3942  enum ast_timelen defunit;
3943 
3944  defunit = va_arg(ap, enum ast_timelen);
3945  /* optional arguments: default value and/or (low, high) */
3946  if (flags & PARSE_DEFAULT) {
3947  def = va_arg(ap, int);
3948  }
3949  if (flags & (PARSE_IN_RANGE | PARSE_OUT_RANGE)) {
3950  low = va_arg(ap, int);
3951  high = va_arg(ap, int);
3952  }
3953  if (ast_strlen_zero(arg)) {
3954  error = 1;
3955  goto timelen_done;
3956  }
3957  error = ast_app_parse_timelen(arg, &x, defunit);
3958  if (error || x < INT_MIN || x > INT_MAX) {
3959  /* Parse error, or type out of int bounds */
3960  error = 1;
3961  goto timelen_done;
3962  }
3963  error = (x < low) || (x > high);
3964  if (flags & PARSE_RANGE_DEFAULTS) {
3965  if (x < low) {
3966  def = low;
3967  } else if (x > high) {
3968  def = high;
3969  }
3970  }
3971  if (flags & PARSE_OUT_RANGE) {
3972  error = !error;
3973  }
3974 timelen_done:
3975  if (result) {
3976  *result = error ? def : x;
3977  }
3978 
3979  ast_debug(3, "extract timelen from [%s] in [%d, %d] gives [%d](%d)\n",
3980  arg, low, high, result ? *result : x, error);
3981  break;
3982  }
3983 
3984  case PARSE_DOUBLE:
3985  {
3986  double *result = p_result;
3987  double x = 0, def = result ? *result : 0, low = -HUGE_VAL, high = HUGE_VAL;
3988  char *endptr = NULL;
3989 
3990  /* optional argument: first default value, then range */
3991  if (flags & PARSE_DEFAULT) {
3992  def = va_arg(ap, double);
3993  }
3994  if (flags & (PARSE_IN_RANGE | PARSE_OUT_RANGE)) {
3995  /* range requested, update bounds */
3996  low = va_arg(ap, double);
3997  high = va_arg(ap, double);
3998  }
3999  if (ast_strlen_zero(arg)) {
4000  error = 1;
4001  goto double_done;
4002  }
4003  errno = 0;
4004  x = strtod(arg, &endptr);
4005  if (*endptr || errno == ERANGE) {
4006  error = 1;
4007  goto double_done;
4008  }
4009  error = (x < low) || (x > high);
4010  if (flags & PARSE_OUT_RANGE) {
4011  error = !error;
4012  }
4013 double_done:
4014  if (result) {
4015  *result = error ? def : x;
4016  }
4017  ast_debug(3, "extract double from [%s] in [%f, %f] gives [%f](%d)\n",
4018  arg, low, high, result ? *result : x, error);
4019  break;
4020  }
4021  case PARSE_ADDR:
4022  {
4023  struct ast_sockaddr *addr = (struct ast_sockaddr *)p_result;
4024 
4025  if (!ast_sockaddr_parse(addr, arg, flags & PARSE_PORT_MASK)) {
4026  error = 1;
4027  }
4028 
4029  ast_debug(3, "extract addr from %s gives %s(%d)\n",
4030  arg, ast_sockaddr_stringify(addr), error);
4031 
4032  break;
4033  }
4034  case PARSE_INADDR: /* TODO Remove this (use PARSE_ADDR instead). */
4035  {
4036  char *port, *buf;
4037  struct sockaddr_in _sa_buf; /* buffer for the result */
4038  struct sockaddr_in *sa = p_result ?
4039  (struct sockaddr_in *)p_result : &_sa_buf;
4040  /* default is either the supplied value or the result itself */
4041  struct sockaddr_in *def = (flags & PARSE_DEFAULT) ?
4042  va_arg(ap, struct sockaddr_in *) : sa;
4043  struct ast_sockaddr addr = { {0,} };
4044 
4045  memset(&_sa_buf, '\0', sizeof(_sa_buf)); /* clear buffer */
4046  /* duplicate the string to strip away the :port */
4047  port = ast_strdupa(arg);
4048  buf = strsep(&port, ":");
4049  sa->sin_family = AF_INET; /* assign family */
4050  /*
4051  * honor the ports flag setting, assign default value
4052  * in case of errors or field unset.
4053  */
4054  flags &= PARSE_PORT_MASK; /* the only flags left to process */
4055  if (port) {
4056  if (flags == PARSE_PORT_FORBID) {
4057  error = 1; /* port was forbidden */
4058  sa->sin_port = def->sin_port;
4059  } else if (flags == PARSE_PORT_IGNORE)
4060  sa->sin_port = def->sin_port;
4061  else /* accept or require */
4062  sa->sin_port = htons(strtol(port, NULL, 0));
4063  } else {
4064  sa->sin_port = def->sin_port;
4065  if (flags == PARSE_PORT_REQUIRE)
4066  error = 1;
4067  }
4068  /* Now deal with host part, even if we have errors before. */
4069  if (ast_sockaddr_resolve_first_af(&addr, buf, PARSE_PORT_FORBID, AF_INET)) {
4070  error = 1;
4071  sa->sin_addr = def->sin_addr;
4072  } else {
4073  struct sockaddr_in tmp;
4074  ast_sockaddr_to_sin(&addr, &tmp);
4075  sa->sin_addr = tmp.sin_addr;
4076  }
4077  ast_debug(3,
4078  "extract inaddr from [%s] gives [%s:%d](%d)\n",
4079  arg, ast_inet_ntoa(sa->sin_addr),
4080  ntohs(sa->sin_port), error);
4081  break;
4082  }
4083  }
4084  va_end(ap);
4085  return error;
4086 }
int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
Parse an IPv4 or IPv6 address string.
Definition: netsock2.c:230
Socket address structure.
Definition: netsock2.h:97
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
int ast_sockaddr_resolve_first_af(struct ast_sockaddr *addr, const char *name, int flag, int family)
Return the first entry from ast_sockaddr_resolve filtered by address family.
Definition: netsock2.c:337
#define ast_debug(level,...)
Log a DEBUG message.
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition: netsock2.h:256
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
Definition: strings.h:161
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
Definition: utils.c:928
#define ast_sockaddr_to_sin(addr, sin)
Converts a struct ast_sockaddr to a struct sockaddr_in.
Definition: netsock2.h:765
int ast_app_parse_timelen(const char *timestr, int *result, enum ast_timelen defunit)
Common routine to parse time lengths, with optional time unit specifier.
Definition: main/app.c:3273
char* ast_realtime_decode_chunk ( char *  chunk)

Remove standard encoding from realtime values, which ensures that a semicolon embedded within a single value is not treated upon retrieval as multiple values.

Parameters
chunkData to be decoded
Returns
The decoded data, in the original buffer
Since
1.8
Warning
This function modifies the original buffer

Definition at line 3795 of file main/config.c.

3796 {
3797  char *orig = chunk;
3798  for (; *chunk; chunk++) {
3799  if (*chunk == '^' && strchr("0123456789ABCDEFabcdef", chunk[1]) && strchr("0123456789ABCDEFabcdef", chunk[2])) {
3800  sscanf(chunk + 1, "%02hhX", (unsigned char *)chunk);
3801  memmove(chunk + 1, chunk + 3, strlen(chunk + 3) + 1);
3802  }
3803  }
3804  return orig;
3805 }
char* ast_realtime_encode_chunk ( struct ast_str **  dest,
ssize_t  maxlen,
const char *  chunk 
)

Encodes a chunk of data for realtime.

Parameters
destDestination buffer
maxlenLength passed through to ast_str_* functions
chunkSource data to be encoded
Returns
Buffer within dest
Since
1.8

Definition at line 3807 of file main/config.c.

References ast_str_append(), ast_str_buffer(), ast_str_reset(), and ast_str_set().

3808 {
3809  if (!strchr(chunk, ';') && !strchr(chunk, '^')) {
3810  ast_str_set(dest, maxlen, "%s", chunk);
3811  } else {
3812  ast_str_reset(*dest);
3813  for (; *chunk; chunk++) {
3814  if (strchr(";^", *chunk)) {
3815  ast_str_append(dest, maxlen, "^%02hhX", *chunk);
3816  } else {
3817  ast_str_append(dest, maxlen, "%c", *chunk);
3818  }
3819  }
3820  }
3821  return ast_str_buffer(*dest);
3822 }
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1139
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1113
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
Definition: strings.h:693
int ast_realtime_is_mapping_defined ( const char *  family)

Determine if a mapping exists for a given family.

Parameters
familywhich family you are looking to see if a mapping exists for
Return values
1if it is mapped
0if it is not

Definition at line 3193 of file main/config.c.

References ast_debug, lock, ast_config_map::name, and SCOPED_MUTEX.

Referenced by ast_named_acl_find().

3194 {
3195  struct ast_config_map *map;
3196  SCOPED_MUTEX(lock, &config_lock);
3197 
3198  for (map = config_maps; map; map = map->next) {
3199  if (!strcasecmp(family, map->name)) {
3200  return 1;
3201  }
3202  }
3203  ast_debug(5, "Failed to find a realtime mapping for %s\n", family);
3204 
3205  return 0;
3206 }
ast_mutex_t lock
#define SCOPED_MUTEX(varname, lock)
scoped lock specialization for mutexes
Definition: lock.h:589
#define ast_debug(level,...)
Log a DEBUG message.
const char * name
Definition: main/config.c:203
int ast_realtime_require_field ( const char *  family,
  ... 
)

Inform realtime what fields that may be stored.

Since
1.6.1
Parameters
familywhich family/config is referenced

This will inform builtin configuration backends that particular fields may be updated during the use of that configuration section. This is mainly to be used during startup routines, to ensure that various fields exist in the backend. The backends may take various actions, such as creating new fields in the data store or warning the administrator that new fields may need to be created, in order to ensure proper function.

The arguments are specified in groups of 3: column name, column type, and column size. The column types are specified as integer constants, defined by the enum require_type. Note that the size is specified as the number of equivalent character fields that a field may take up, even if a field is otherwise specified as an integer type. This is due to the fact that some fields have historically been specified as character types, even if they contained integer values.

A family should always specify its fields to the minimum necessary requirements to fulfill all possible values (within reason; for example, a timeout value may reasonably be specified as an INTEGER2, with size 5. Even though values above 32767 seconds are possible, they are unlikely to be useful, and we should not complain about that size).

Return values
0Required fields met specified standards
-1One or more fields was missing or insufficient
Note
You should use the constant SENTINEL to terminate arguments, in order to preserve cross-platform compatibility.

TODO The return value of this function is routinely ignored. Ignoring the return value means that it's mostly pointless to be calling this. You'll see some warning messages potentially, but that's it.

XXX This function is super useful for detecting configuration problems early, but unfortunately, the latest in configuration management, sorcery, doesn't work well with this. Users of sorcery are familiar with the fields they will need to write but don't know if realtime is being used. Sorcery knows what storage mechanism is being used but has no high-level knowledge of what sort of data is going to be written.

Definition at line 3549 of file main/config.c.

References find_engine().

Referenced by change_password_realtime(), and load_module().

3550 {
3551  struct ast_config_engine *eng;
3552  char db[256];
3553  char table[256];
3554  va_list ap, aq;
3555  int res = -1, i;
3556 
3557  va_start(ap, family);
3558  for (i = 1; ; i++) {
3559  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3560  va_copy(aq, ap);
3561  /* If the require succeeds, it returns 0. */
3562  if (eng->require_func && !(res = eng->require_func(db, table, aq))) {
3563  va_end(aq);
3564  break;
3565  }
3566  va_end(aq);
3567  } else {
3568  break;
3569  }
3570  }
3571  va_end(ap);
3572 
3573  return res;
3574 }
Configuration engine structure, used to define realtime drivers.
static struct ast_config_engine * find_engine(const char *family, int priority, char *database, int dbsiz, char *table, int tabsiz)
Find realtime engine for realtime family.
Definition: main/config.c:3209
int ast_store_realtime ( const char *  family,
  ... 
)

Create realtime configuration.

Parameters
familywhich family/config to be created

This function is used to create a parameter in realtime configuration space.

Returns
Number of rows affected, or -1 on error.
Note
On the MySQL engine only, for reasons of backwards compatibility, the return value is the insert ID. This value is nonportable and may be changed in a future version to match the other engines.
You should use the constant SENTINEL to terminate arguments, in order to preserve cross-platform compatibility.

Definition at line 3740 of file main/config.c.

References ast_store_realtime_fields(), ast_variables_destroy(), and RAII_VAR.

Referenced by copy_plain_file(), and leave_voicemail().

3741 {
3742  RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
3743  va_list ap;
3744 
3745  va_start(ap, family);
3746  realtime_arguments_to_fields(ap, &fields);
3747  va_end(ap);
3748 
3749  if (!fields) {
3750  return -1;
3751  }
3752 
3753  return ast_store_realtime_fields(family, fields);
3754 }
Structure for variables, used for configurations and for channel variables.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: main/config.c:589
int ast_store_realtime_fields(const char *family, const struct ast_variable *fields)
Create realtime configuration.
Definition: main/config.c:3719
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941
int ast_store_realtime_fields ( const char *  family,
const struct ast_variable fields 
)

Create realtime configuration.

Parameters
familywhich family/config to be created
fieldsfields themselves

This function is used to create a parameter in realtime configuration space.

Returns
Number of rows affected, or -1 on error.
Note
On the MySQL engine only, for reasons of backwards compatibility, the return value is the insert ID. This value is nonportable and may be changed in a future version to match the other engines.

Definition at line 3719 of file main/config.c.

References find_engine().

Referenced by ast_store_realtime().

3720 {
3721  struct ast_config_engine *eng;
3722  int res = -1, i;
3723  char db[256];
3724  char table[256];
3725 
3726  for (i = 1; ; i++) {
3727  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3728  /* If the store succeeds, it returns >= 0*/
3729  if (eng->store_func && ((res = eng->store_func(db, table, fields)) >= 0)) {
3730  break;
3731  }
3732  } else {
3733  break;
3734  }
3735  }
3736 
3737  return res;
3738 }
Configuration engine structure, used to define realtime drivers.
static struct ast_config_engine * find_engine(const char *family, int priority, char *database, int dbsiz, char *table, int tabsiz)
Find realtime engine for realtime family.
Definition: main/config.c:3209
int ast_unload_realtime ( const char *  family)

Release any resources cached for a realtime family.

Since
1.6.1
Parameters
familywhich family/config to destroy

Various backends may cache attributes about a realtime data storage facility; on reload, a front end resource may request to purge that cache.

Return values
0If any cache was purged
-1If no cache was found

Definition at line 3576 of file main/config.c.

References find_engine().

Referenced by load_config_force(), and set_config().

3577 {
3578  struct ast_config_engine *eng;
3579  char db[256];
3580  char table[256];
3581  int res = -1, i;
3582 
3583  for (i = 1; ; i++) {
3584  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3585  if (eng->unload_func) {
3586  /* Do this for ALL engines */
3587  res = eng->unload_func(db, table);
3588  }
3589  } else {
3590  break;
3591  }
3592  }
3593  return res;
3594 }
Configuration engine structure, used to define realtime drivers.
static struct ast_config_engine * find_engine(const char *family, int priority, char *database, int dbsiz, char *table, int tabsiz)
Find realtime engine for realtime family.
Definition: main/config.c:3209
int ast_update2_realtime ( const char *  family,
  ... 
)

Update realtime configuration.

Parameters
familywhich family/config to be updated

This function is used to update a parameter in realtime configuration space. It includes the ability to lookup a row based upon multiple key criteria. As a result, this function includes two sentinel values, one to terminate lookup values and the other to terminate the listing of fields to update.

Returns
Number of rows affected, or -1 on error.
Note
You should use the constant SENTINEL to terminate arguments, in order to preserve cross-platform compatibility.

Definition at line 3695 of file main/config.c.

References ast_update2_realtime_fields(), ast_variables_destroy(), and RAII_VAR.

Referenced by change_password_realtime().

3696 {
3697  RAII_VAR(struct ast_variable *, lookup_fields, NULL, ast_variables_destroy);
3698  RAII_VAR(struct ast_variable *, update_fields, NULL, ast_variables_destroy);
3699  va_list ap;
3700 
3701  va_start(ap, family);
3702  /* XXX: If we wanted to pass no lookup fields (select all), we'd be
3703  * out of luck. realtime_arguments_to_fields expects at least one key
3704  * value pair. */
3705  realtime_arguments_to_fields(ap, &lookup_fields);
3706  va_end(ap);
3707 
3708  va_start(ap, family);
3709  realtime_arguments_to_fields2(ap, 1, &update_fields);
3710  va_end(ap);
3711 
3712  if (!lookup_fields || !update_fields) {
3713  return -1;
3714  }
3715 
3716  return ast_update2_realtime_fields(family, lookup_fields, update_fields);
3717 }
int ast_update2_realtime_fields(const char *family, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields)
Update realtime configuration.
Definition: main/config.c:3675
Structure for variables, used for configurations and for channel variables.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: main/config.c:589
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941
int ast_update2_realtime_fields ( const char *  family,
const struct ast_variable lookup_fields,
const struct ast_variable update_fields 
)

Update realtime configuration.

Parameters
familywhich family/config to be updated
lookup_fieldsfields used to look up entries
update_fieldsfields to update

This function is used to update a parameter in realtime configuration space. It includes the ability to lookup a row based upon multiple key criteria. As a result, this function includes two sentinel values, one to terminate lookup values and the other to terminate the listing of fields to update.

Returns
Number of rows affected, or -1 on error.

Definition at line 3675 of file main/config.c.

References find_engine().

Referenced by ast_update2_realtime().

3676 {
3677  struct ast_config_engine *eng;
3678  int res = -1, i;
3679  char db[256];
3680  char table[256];
3681 
3682  for (i = 1; ; i++) {
3683  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3684  if (eng->update2_func && !(res = eng->update2_func(db, table, lookup_fields, update_fields))) {
3685  break;
3686  }
3687  } else {
3688  break;
3689  }
3690  }
3691 
3692  return res;
3693 }
Configuration engine structure, used to define realtime drivers.
static struct ast_config_engine * find_engine(const char *family, int priority, char *database, int dbsiz, char *table, int tabsiz)
Find realtime engine for realtime family.
Definition: main/config.c:3209
int ast_update_realtime ( const char *  family,
const char *  keyfield,
const char *  lookup,
  ... 
)

Update realtime configuration.

Parameters
familywhich family/config to be updated
keyfieldwhich field to use as the key
lookupwhich value to look for in the key field to match the entry.

This function is used to update a parameter in realtime configuration space.

Returns
Number of rows affected, or -1 on error.
Note
You should use the constant SENTINEL to terminate arguments, in order to preserve cross-platform compatibility.

Definition at line 3659 of file main/config.c.

References ast_update_realtime_fields(), ast_variables_destroy(), and RAII_VAR.

Referenced by leave_voicemail(), and rename_file().

3660 {
3661  RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
3662  va_list ap;
3663 
3664  va_start(ap, lookup);
3665  realtime_arguments_to_fields(ap, &fields);
3666  va_end(ap);
3667 
3668  if (!fields) {
3669  return -1;
3670  }
3671 
3672  return ast_update_realtime_fields(family, keyfield, lookup, fields);
3673 }
Structure for variables, used for configurations and for channel variables.
int ast_update_realtime_fields(const char *family, const char *keyfield, const char *lookup, const struct ast_variable *fields)
Update realtime configuration.
Definition: main/config.c:3638
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: main/config.c:589
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941
int ast_update_realtime_fields ( const char *  family,
const char *  keyfield,
const char *  lookup,
const struct ast_variable fields 
)

Update realtime configuration.

Parameters
familywhich family/config to be updated
keyfieldwhich field to use as the key
lookupwhich value to look for in the key field to match the entry.
fieldsfields to update

This function is used to update a parameter in realtime configuration space.

Returns
Number of rows affected, or -1 on error.

Definition at line 3638 of file main/config.c.

References find_engine().

Referenced by ast_update_realtime().

3639 {
3640  struct ast_config_engine *eng;
3641  int res = -1, i;
3642  char db[256];
3643  char table[256];
3644 
3645  for (i = 1; ; i++) {
3646  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3647  /* If the update succeeds, it returns >= 0. */
3648  if (eng->update_func && ((res = eng->update_func(db, table, keyfield, lookup, fields)) >= 0)) {
3649  break;
3650  }
3651  } else {
3652  break;
3653  }
3654  }
3655 
3656  return res;
3657 }
Configuration engine structure, used to define realtime drivers.
static struct ast_config_engine * find_engine(const char *family, int priority, char *database, int dbsiz, char *table, int tabsiz)
Find realtime engine for realtime family.
Definition: main/config.c:3209
struct ast_variable* ast_variable_browse_filtered ( const struct ast_config config,
const char *  category_name,
const char *  filter 
)

Browse variables.

Parameters
configWhich config structure you wish to "browse"
category_nameWhich category to "browse"
filteran optional comma-separated list of <name_regex>=<value_regex> pairs. Only categories with matching variables will be browsed. The special name 'TEMPLATES' can be used with the special values 'include' or 'restrict' to include templates in the result or restrict the result to only templates.

Somewhat similar in intent as the ast_category_browse. List variables of config file category

Return values
ast_variablelist on success
NULLon failure
const char* ast_variable_find ( const struct ast_category category,
const char *  variable 
)

Gets a variable value from a specific category structure by name.

Parameters
categorycategory structure under which the variable lies
variablewhich variable you wish to get the data for

Goes through a given category and searches for the given variable

Return values
Thevariable value on success
NULLif unable to find it.

Definition at line 824 of file main/config.c.

References ast_variable_find_in_list(), and ast_category::root.

Referenced by ast_variable_retrieve_filtered().

825 {
826  return ast_variable_find_in_list(category->root, variable);
827 }
struct ast_variable * root
Definition: main/config.c:240
const char * ast_variable_find_in_list(const struct ast_variable *list, const char *variable)
Gets the value of a variable from a variable list by name.
Definition: main/config.c:919
const char* ast_variable_find_in_list ( const struct ast_variable list,
const char *  variable 
)

Gets the value of a variable from a variable list by name.

Parameters
listvariable list to search
variablewhich variable you wish to get the data for

Goes through a given variable list and searches for the given variable

Return values
Thevariable value on success
NULLif unable to find it.

Definition at line 919 of file main/config.c.

References ast_variable::name, ast_variable::next, and ast_variable::value.

Referenced by ast_sorcery_changeset_create(), and ast_variable_find().

920 {
921  const struct ast_variable *v;
922 
923  for (v = list; v; v = v->next) {
924  if (!strcasecmp(variable, v->name)) {
925  return v->value;
926  }
927  }
928  return NULL;
929 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
const char* ast_variable_find_last_in_list ( const struct ast_variable list,
const char *  variable 
)

Gets the value of the LAST occurrence of a variable from a variable list.

Parameters
listThe ast_variable list to search
variableThe name of the ast_variable you wish to fetch data for

Iterates over a given ast_variable list to search for the last occurrence of an ast_variable entry with a name attribute matching the given name (variable). This is useful if the list has duplicate entries (such as in cases where entries are created by a template)

Return values
Thevariable value on success
NULLif unable to find it.

Definition at line 931 of file main/config.c.

References ast_variable::name, ast_variable::next, and ast_variable::value.

Referenced by is_variable_true().

932 {
933  const struct ast_variable *v;
934  const char *found = NULL;
935 
936  for (v = list; v; v = v->next) {
937  if (!strcasecmp(variable, v->name)) {
938  found = v->value;
939  }
940  }
941  return found;
942 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
const struct ast_variable* ast_variable_find_variable_in_list ( const struct ast_variable list,
const char *  variable_name 
)

Gets a variable from a variable list by name.

Since
13.9.0
Parameters
listvariable list to search
variable_namename you wish to get the data for

Goes through a given variable list and searches for the given variable

Return values
Thevariable (not the value) on success
NULLif unable to find it.

Definition at line 829 of file main/config.c.

References ast_variable::name, and ast_variable::next.

Referenced by ast_variable_lists_match().

830 {
831  const struct ast_variable *v;
832 
833  for (v = list; v; v = v->next) {
834  if (!strcasecmp(variable_name, v->name)) {
835  return v;
836  }
837  }
838  return NULL;
839 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
struct ast_variable* ast_variable_list_append_hint ( struct ast_variable **  head,
struct ast_variable search_hint,
struct ast_variable new_var 
)

Appends a variable list to the end of another list.

Parameters
headA pointer to an ast_variable * of the existing variable list head. May NOT be NULL but the content may be to initialize a new list. If so, upon return, this parameter will be updated with a pointer to the new list head.
search_hintThe place in the current list to start searching for the end of the list. Might help performance on longer lists. If NULL, it defaults to head.
new_varThe head of the new variable list to be appended
Returns
The tail of the resulting list.
Note
If the existing *head is NULL, it will be updated to new_var. This allows you to call ast_variable_list_append in a loop or callback without initializing the list first.

Definition at line 646 of file main/config.c.

References ast_variable::next.

Referenced by ast_json_to_ast_variables(), and ast_sorcery_objectset_create2().

647 {
648  struct ast_variable *curr;
649  struct ast_variable *sh = search_hint;
650  ast_assert(head != NULL);
651 
652  if (!*head) {
653  *head = newvar;
654  } else {
655  if (sh == NULL) {
656  sh = *head;
657  }
658  for (curr = sh; curr->next; curr = curr->next);
659  curr->next = newvar;
660  }
661 
662  for (curr = newvar; curr->next; curr = curr->next);
663 
664  return curr;
665 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
struct ast_variable* ast_variable_list_from_quoted_string ( const char *  input,
const char *  item_separator,
const char *  name_value_separator,
const char *  quote_str 
)

Parse a string into an ast_variable list. The reverse of ast_variable_list_join.

Parameters
inputThe name-value pair string to parse.
item_separatorThe string used to separate the list items. Only the first character in the string will be used. If NULL, "," will be used.
name_value_separatorThe string used to separate each item's name and value. Only the first character in the string will be used. If NULL, "=" will be used.
quote_strThe string used to quote values. Only the first character in the string will be used. If NULL, '"' will be used.
Return values
Apointer to a list of ast_variables.
NULLif there was an error or no variables could be parsed.

Definition at line 726 of file main/config.c.

References ast_strdupa, ast_strip(), AST_STRSEP_ALL, ast_strsep_quoted(), and ast_variables_destroy().

Referenced by ast_variable_list_from_string().

728 {
729  char item_sep;
730  char nv_sep;
731  char quote;
732  struct ast_variable *new_list = NULL;
733  struct ast_variable *new_var = NULL;
734  char *item_string;
735  char *item;
736  char *item_name;
737  char *item_value;
738 
739  if (ast_strlen_zero(input)) {
740  return NULL;
741  }
742 
743  item_sep = ast_strlen_zero(item_separator) ? ',' : item_separator[0];
744  nv_sep = ast_strlen_zero(name_value_separator) ? '=' : name_value_separator[0];
745  quote = ast_strlen_zero(quote_str) ? '"' : quote_str[0];
746  item_string = ast_strip(ast_strdupa(input));
747 
748  while ((item = ast_strsep_quoted(&item_string, item_sep, quote, AST_STRSEP_ALL))) {
749  item_name = ast_strsep_quoted(&item, nv_sep, quote, AST_STRSEP_ALL);
750  if (!item_name) {
751  ast_variables_destroy(new_list);
752  return NULL;
753  }
754 
755  item_value = ast_strsep_quoted(&item, nv_sep, quote, AST_STRSEP_ALL);
756 
757  new_var = ast_variable_new(item_name, item_value ?: "", "");
758  if (!new_var) {
759  ast_variables_destroy(new_list);
760  return NULL;
761  }
762  ast_variable_list_append(&new_list, new_var);
763  }
764  return new_list;
765 }
Structure for variables, used for configurations and for channel variables.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:223
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: main/config.c:589
char * ast_strsep_quoted(char **s, const char sep, const char quote, uint32_t flags)
Like ast_strsep() except you can specify a specific quote character.
Definition: utils.c:1899
struct ast_variable* ast_variable_list_from_string ( const char *  input,
const char *  item_separator,
const char *  name_value_separator 
)

Parse a string into an ast_variable list. The reverse of ast_variable_list_join.

Parameters
inputThe name-value pair string to parse.
item_separatorThe string used to separate the list items. Only the first character in the string will be used. If NULL, "," will be used.
name_value_separatorThe string used to separate each item's name and value. Only the first character in the string will be used. If NULL, "=" will be used.
Return values
Apointer to a list of ast_variables.
NULLif there was an error or no variables could be parsed.

Definition at line 767 of file main/config.c.

References ast_variable_list_from_quoted_string().

769 {
770  return ast_variable_list_from_quoted_string(input, item_separator, name_value_separator, NULL);
771 }
struct ast_variable * ast_variable_list_from_quoted_string(const char *input, const char *item_separator, const char *name_value_separator, const char *quote_str)
Parse a string into an ast_variable list. The reverse of ast_variable_list_join.
Definition: main/config.c:726
struct ast_str* ast_variable_list_join ( const struct ast_variable head,
const char *  item_separator,
const char *  name_value_separator,
const char *  quote_char,
struct ast_str **  str 
)

Join an ast_variable list with specified separators and quoted values.

Parameters
headA pointer to an ast_variable list head.
item_separatorThe string to use to separate the list items. If NULL, "," will be used.
name_value_separatorThe string to use to separate each item's name and value. If NULL, "=" will be used.
strA pointer to a pre-allocated ast_str in which to put the results. If NULL, one will be allocated and returned.
quote_charThe quote char to use for the values. May be NULL or empty for no quoting.
Return values
Apointer to the result ast_str. This may NOT be the same as the pointer passed in if the original ast_str wasn't large enough to hold the result. Regardless, the pointer MUST be freed after use.
NULLif there was an error.

Definition at line 700 of file main/config.c.

References AST_MAX_USER_FIELD, ast_str_append(), ast_str_create, ast_variable::name, ast_variable::next, S_OR, and ast_variable::value.

702 {
703  struct ast_variable *var = (struct ast_variable *)head;
704  struct ast_str *local_str = NULL;
705 
706  if (str == NULL || *str == NULL) {
707  local_str = ast_str_create(AST_MAX_USER_FIELD);
708  if (!local_str) {
709  return NULL;
710  }
711  } else {
712  local_str = *str;
713  }
714 
715  for (; var; var = var->next) {
716  ast_str_append(&local_str, 0, "%s%s%s%s%s%s", var->name, name_value_separator, S_OR(quote_char, ""),
717  var->value, S_OR(quote_char, ""), var->next ? item_separator : "");
718  }
719 
720  if (str != NULL) {
721  *str = local_str;
722  }
723  return local_str;
724 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1139
Support for dynamic strings.
Definition: strings.h:623
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:80
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
#define AST_MAX_USER_FIELD
Definition: channel.h:174
int ast_variable_list_replace ( struct ast_variable **  head,
struct ast_variable replacement 
)

Replace a variable in the given list with a new value.

Since
13.30.0
Parameters
headA pointer to an ast_variable * of the existing variable list head. May NOT be NULL but the content may be to initialize a new list. If so, upon return, this parameter will be updated with a pointer to the new list head.
replacementThe variable that replaces another variable in the list with the same name.
Return values
0if a variable was replaced in the list
-1if no replacement occured
Note
The variable name comparison is performed case-sensitively
If a variable is replaced, its memory is freed.

Definition at line 667 of file main/config.c.

References ast_variable::name, and ast_variable::next.

Referenced by build_user(), and mkintf().

668 {
669  struct ast_variable *v, **prev = head;
670 
671  for (v = *head; v; prev = &v->next, v = v->next) {
672  if (!strcmp(v->name, replacement->name)) {
673  replacement->next = v->next;
674  *prev = replacement;
675  ast_free(v);
676  return 0;
677  }
678  }
679 
680  return -1;
681 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
int ast_variable_list_replace_variable ( struct ast_variable **  head,
struct ast_variable oldvar,
struct ast_variable newvar 
)

Replace a variable in the given list with a new variable.

Parameters
headA pointer to the current variable list head. Since the variable to be replaced, this pointer may be updated with the new head.
oldvarA pointer to the existing variable to be replaced.
newvarA pointer to the new variable that will replace the old one.
Return values
0if a variable was replaced in the list
-1if no replacement occured
Note
The search for the old variable is done simply on the pointer.
If a variable is replaced, its memory is freed.

Definition at line 683 of file main/config.c.

References ast_variable::next.

685 {
686  struct ast_variable *v, **prev = head;
687 
688  for (v = *head; v; prev = &v->next, v = v->next) {
689  if (v == old) {
690  new->next = v->next;
691  *prev = new;
692  ast_free(v);
693  return 0;
694  }
695  }
696 
697  return -1;
698 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
struct ast_variable* ast_variable_list_sort ( struct ast_variable head)

Performs an in-place sort on the variable list by ascending name.

Parameters
headThe variable list head
Returns
The new list head

Definition at line 620 of file main/config.c.

References ast_variable::name, and ast_variable::next.

621 {
622  struct ast_variable *p, *q;
623  struct ast_variable top;
624  int changed = 1;
625  memset(&top, 0, sizeof(top));
626  top.next = start;
627  if (start != NULL && start->next != NULL) {
628  while (changed) {
629  changed = 0;
630  q = &top;
631  p = top.next;
632  while (p->next != NULL) {
633  if (p->next != NULL && strcmp(p->name, p->next->name) > 0) {
634  q->next = variable_list_switch(p, p->next);
635  changed = 1;
636  }
637  q = p;
638  if (p->next != NULL)
639  p = p->next;
640  }
641  }
642  }
643  return top.next;
644 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
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.

Since
13.9.0
Parameters
leftVariable list to test
rightVariable list with an optional realtime-style operator in the names
exact_matchIf true, all variables in left must match all variables in right and vice versa. This does exact value matches only. Operators aren't supported. Except for order, the left and right lists must be equal.

If false, every variable in the right list must match some variable in the left list using the operators supplied. Variables in the left list that aren't in the right list are ignored for matching purposes.

Return values
1matches
0doesn't match

Iterates over the variable lists calling ast_variables_match. If any match fails or a variable in the right list isn't in the left list, 0 is returned.

Definition at line 861 of file main/config.c.

References ast_strdup, ast_variable_find_variable_in_list(), ast_variables_match(), ast_variable::name, ast_variable::next, and ast_variable::value.

Referenced by object_type_loaded_observer(), and sorcery_astdb_retrieve_fields_common().

862 {
863  const struct ast_variable *field;
864  int right_count = 0;
865  int left_count = 0;
866 
867  if (left == right) {
868  return 1;
869  }
870 
871  if (!(left && right)) {
872  return 0;
873  }
874 
875  for (field = right; field; field = field->next) {
876  char *space = strrchr(field->name, ' ');
877  const struct ast_variable *old;
878  char * name = (char *)field->name;
879 
880  if (space) {
881  name = ast_strdup(field->name);
882  if (!name) {
883  return 0;
884  }
885  name[space - field->name] = '\0';
886  }
887 
888  old = ast_variable_find_variable_in_list(left, name);
889  if (name != field->name) {
890  ast_free(name);
891  }
892 
893  if (exact_match) {
894  if (!old || strcmp(old->value, field->value)) {
895  return 0;
896  }
897  } else {
898  if (!ast_variables_match(old, field)) {
899  return 0;
900  }
901  }
902 
903  right_count++;
904  }
905 
906  if (exact_match) {
907  for (field = left; field; field = field->next) {
908  left_count++;
909  }
910 
911  if (right_count != left_count) {
912  return 0;
913  }
914  }
915 
916  return 1;
917 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
int ast_variables_match(const struct ast_variable *left, const struct ast_variable *right)
Tests 2 variable values to see if they match.
Definition: main/config.c:841
const struct ast_variable * ast_variable_find_variable_in_list(const struct ast_variable *list, const char *variable_name)
Gets a variable from a variable list by name.
Definition: main/config.c:829
const char* ast_variable_retrieve_filtered ( struct ast_config config,
const char *  category,
const char *  variable,
const char *  filter 
)

Gets a variable by context and variable names.

Parameters
configwhich (opened) config to use
categorycategory under which the variable lies
variablewhich variable you wish to get the data for
filteran optional comma-separated list of <name_regex>=<value_regex> pairs. Only categories with matching variables will be searched. The special name 'TEMPLATES' can be used with the special values 'include' or 'restrict' to include templates in the result or restrict the result to only templates.
Return values
Thevariable value on success
NULLif unable to find it.

Definition at line 808 of file main/config.c.

References ast_category_browse_filtered(), and ast_variable_find().

810 {
811  struct ast_category *cat = NULL;
812  const char *value;
813 
814  while ((cat = ast_category_browse_filtered(config, category, cat, filter))) {
815  value = ast_variable_find(cat, variable);
816  if (value) {
817  return value;
818  }
819  }
820 
821  return NULL;
822 }
const char * ast_variable_find(const struct ast_category *category, const char *variable)
Gets a variable value from a specific category structure by name.
Definition: main/config.c:824
static int filter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:807
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.
Definition: main/config.c:1424
int ast_variable_update ( struct ast_category category,
const char *  variable,
const char *  value,
const char *  match,
unsigned int  object 
)

Update variable value within a config.

Parameters
categoryCategory element within the config
variableName of the variable to change
valueNew value of the variable
matchIf set, previous value of the variable (if NULL or zero-length, no matching will be done)
objectBoolean of whether to make the new variable an object
Returns
0 on success or -1 on failure.

Definition at line 1533 of file main/config.c.

References ast_variable::file, ast_category::last, ast_variable::name, ast_variable::next, ast_category::root, and ast_variable::value.

Referenced by handle_updates(), process_text_line(), vm_change_password(), and vm_forwardoptions().

1535 {
1536  struct ast_variable *cur, *prev=NULL, *newer=NULL;
1537 
1538  for (cur = category->root; cur; prev = cur, cur = cur->next) {
1539  if (strcasecmp(cur->name, variable) ||
1540  (!ast_strlen_zero(match) && strcasecmp(cur->value, match)))
1541  continue;
1542 
1543  if (!(newer = ast_variable_new(variable, value, cur->file)))
1544  return -1;
1545 
1546  ast_variable_move(newer, cur);
1547  newer->object = newer->object || object;
1548 
1549  /* Replace the old node in the list with the new node. */
1550  newer->next = cur->next;
1551  if (prev)
1552  prev->next = newer;
1553  else
1554  category->root = newer;
1555  if (category->last == cur)
1556  category->last = newer;
1557 
1558  ast_variable_destroy(cur);
1559 
1560  return 0;
1561  }
1562 
1563  /* Could not find variable to update */
1564  return -1;
1565 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
struct ast_variable * root
Definition: main/config.c:240
struct ast_variable * last
Definition: main/config.c:242
static void ast_variables_destroy ( struct ast_variable var)

Free variable list.

Parameters
varthe linked list of variables to free

This function frees a list of variables.

Definition at line 1262 of file extconf.c.

References ast_variables_destroy(), and ast_variable::next.

Referenced by aco_set_defaults(), ast_aeap_client_configs_get(), ast_ari_asterisk_update_object(), ast_ari_channels_create(), ast_ari_channels_originate(), ast_ari_channels_originate_with_id(), ast_ari_endpoints_refer(), ast_ari_endpoints_refer_to_endpoint(), ast_ari_endpoints_send_message(), ast_ari_endpoints_send_message_to_endpoint(), ast_category_empty(), ast_config_destroy(), ast_destroy_realtime(), ast_http_get_cookies(), ast_http_manid_from_vars(), ast_json_to_ast_variables(), ast_load_realtime_multientry(), ast_sorcery_changeset_create(), ast_sorcery_copy(), ast_sorcery_diff(), ast_sorcery_object_set_extended(), ast_sorcery_objectset_apply(), ast_sorcery_objectset_json_create(), ast_store_realtime(), ast_stream_free(), ast_stream_get_metadata_list(), ast_update2_realtime(), ast_update_realtime(), ast_variable_list_from_quoted_string(), ast_variables_destroy(), ast_variables_dup(), copy_plain_file(), fields_handler(), find_load_queue_rt_friendly(), find_user_realtime(), generic_http_callback(), get_object_variables(), handle_showchan(), ldap_loadentry(), leave_queue(), mkintf(), object_type_loaded_observer(), queue_function_queuegetchannel(), queue_function_queuewaitingcount(), realtime_ldap_base(), realtime_ldap_base_ap(), realtime_ldap_result_to_vars(), realtime_odbc(), realtime_peer(), realtime_user(), row_to_varlist(), sorcery_astdb_filter_objectset(), sorcery_astdb_retrieve_fields_common(), sorcery_config_destructor(), sorcery_is_criteria_met(), sorcery_realtime_filter_objectset(), table_configs_free(), test_sorcery_object_destroy(), and test_sorcery_transform().

1263 {
1264  struct ast_variable *vn;
1265 
1266  while (v) {
1267  vn = v;
1268  v = v->next;
1269  free(vn);
1270  }
1271 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
struct ast_variable* ast_variables_dup ( struct ast_variable var)

Duplicate variable list.

Parameters
varthe linked list of variables to clone
Returns
A duplicated list which you'll need to free with ast_variables_destroy or NULL when out of memory.
Note
Do not depend on this to copy more than just name, value and filename (the arguments to ast_variables_new).

Definition at line 543 of file main/config.c.

References ast_variables_destroy(), ast_variable::file, ast_variable::name, ast_variable::next, and ast_variable::value.

Referenced by ast_config_copy().

544 {
545  struct ast_variable *cloned;
546  struct ast_variable *tmp;
547 
548  if (!(cloned = ast_variable_new(var->name, var->value, var->file))) {
549  return NULL;
550  }
551 
552  tmp = cloned;
553 
554  while ((var = var->next)) {
555  if (!(tmp->next = ast_variable_new(var->name, var->value, var->file))) {
556  ast_variables_destroy(cloned);
557  return NULL;
558  }
559  tmp = tmp->next;
560  }
561 
562  return cloned;
563 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: main/config.c:589
int ast_variables_match ( const struct ast_variable left,
const struct ast_variable right 
)

Tests 2 variable values to see if they match.

Since
13.9.0
Parameters
leftVariable to test
rightVariable to match against with an optional realtime-style operator in the name
Return values
1matches
0doesn't match

The values of the variables are passed to ast_strings_match. If right->name is suffixed with a space and an operator, that operator is also passed to ast_strings_match.

Examples:

left->name = "id" (ignored) left->value = "abc" right->name = "id regex" (id is ignored) right->value = "a[bdef]c"

will result in ast_strings_match("abc", "regex", "a[bdef]c") which will return 1.

left->name = "id" (ignored) left->value = "abc" right->name = "id" (ignored) right->value = "abc"

will result in ast_strings_match("abc", NULL, "abc") which will return 1.

See the documentation for ast_strings_match for the valid operators.

Definition at line 841 of file main/config.c.

References ast_strdupa, ast_strings_match(), ast_variable::name, and ast_variable::value.

Referenced by ast_variable_lists_match().

842 {
843  char *op;
844 
845  if (left == right) {
846  return 1;
847  }
848 
849  if (!(left && right)) {
850  return 0;
851  }
852 
853  op = strrchr(right->name, ' ');
854  if (op) {
855  op++;
856  }
857 
858  return ast_strings_match(left->value, op ? ast_strdupa(op) : NULL, right->value);
859 }
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
int ast_strings_match(const char *left, const char *op, const char *right)
Compares 2 strings using realtime-style operators.
Definition: strings.c:247
struct ast_variable* ast_variables_reverse ( struct ast_variable var)

Reverse a variable list.

Parameters
varthe linked list of variables to reverse
Returns
The head of the reversed variable list
Note
The variable list var is not preserved in this function and should not be used after reversing it.

Definition at line 565 of file main/config.c.

References ast_variable::next.

Referenced by astman_get_variables_order().

566 {
567  struct ast_variable *var1, *var2;
568 
569  var1 = var;
570 
571  if (!var1 || !var1->next) {
572  return var1;
573  }
574 
575  var2 = var1->next;
576  var1->next = NULL;
577 
578  while (var2) {
579  struct ast_variable *next = var2->next;
580 
581  var2->next = var1;
582  var1 = var2;
583  var2 = next;
584  }
585 
586  return var1;
587 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
int register_config_cli ( void  )

Exposed initialization method for core process.

This method is intended for use only with the core initialization and is not designed to be called from any user applications.

Definition at line 4236 of file main/config.c.

References ast_cli_register_multiple, and ast_register_cleanup().

4237 {
4238  ast_cli_register_multiple(cli_config, ARRAY_LEN(cli_config));
4239  /* This is separate from the module load so cleanup can happen very late. */
4240  ast_register_cleanup(config_shutdown);
4241  return 0;
4242 }
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19