Asterisk - The Open Source Telephony Project GIT-master-b023714
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Enumerations | Functions
config.h File Reference

Configuration File Parser. More...

#include "asterisk/utils.h"
#include "asterisk/inline_api.h"
Include dependency graph for include/asterisk/config.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.
 
#define ast_config_load(filename, flags)   ast_config_load2(filename, AST_MODULE, flags)
 Load a config file.
 
#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_RT_NOT_FOUND   (void *)-1
 
#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
 
#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.
 
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.
 
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.
 
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. More...
 
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. More...
 

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.
 
char * ast_category_browse (struct ast_config *config, const char *prev_name)
 Browse categories.
 
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.
 
struct ast_categoryast_category_delete (struct ast_config *cfg, struct ast_category *cat)
 Delete a category.
 
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.
 
int ast_category_exist (const struct ast_config *config, const char *category_name, const char *filter)
 Check for category duplicates.
 
struct ast_variableast_category_first (struct ast_category *cat)
 given a pointer to a category, return the root variable.
 
struct ast_categoryast_category_get (const struct ast_config *config, const char *category_name, const char *filter)
 Retrieve a category if it exists.
 
const char * ast_category_get_name (const struct ast_category *category)
 Return the name of the category.
 
struct ast_strast_category_get_templates (const struct ast_category *category)
 Return the template names this category inherits from.
 
int ast_category_inherit (struct ast_category *existing, const struct ast_category *base)
 Applies base (template) to category.
 
int ast_category_insert (struct ast_config *config, struct ast_category *cat, const char *match)
 Inserts new category.
 
int ast_category_is_template (const struct ast_category *category)
 Check if category is a template.
 
struct ast_categoryast_category_new (const char *name, const char *in_file, int lineno)
 Create a category.
 
struct ast_categoryast_category_new_template (const char *name, const char *in_file, int lineno)
 Create a category making it a template.
 
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
 
int ast_check_realtime (const char *family)
 Check if realtime engine is configured for family.
 
struct ast_configast_config_copy (const struct ast_config *orig)
 Copies the contents of one ast_config into another.
 
void ast_config_destroy (struct ast_config *cfg)
 Destroys a config.
 
int ast_config_engine_deregister (struct ast_config_engine *del)
 Deregister config engine.
 
int ast_config_engine_register (struct ast_config_engine *newconfig)
 Register config engine.
 
struct ast_categoryast_config_get_current_category (const struct ast_config *cfg)
 Retrieve the current category name being built.
 
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.
 
void ast_config_hook_unregister (const char *name)
 Unregister a config hook.
 
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.
 
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.
 
void ast_config_set_current_category (struct ast_config *cfg, const struct ast_category *cat)
 Set the category within the configuration as being current.
 
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.
 
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.
 
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.
 
int ast_destroy_realtime (const char *family, const char *keyfield, const char *lookup,...) attribute_sentinel
 Destroy realtime configuration.
 
int ast_destroy_realtime_fields (const char *family, const char *keyfield, const char *lookup, const struct ast_variable *fields)
 Destroy realtime configuration.
 
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 include_type, 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.
 
struct ast_configast_load_realtime_multientry (const char *family,...) attribute_sentinel
 Retrieve realtime configuration.
 
struct ast_configast_load_realtime_multientry_fields (const char *family, const struct ast_variable *fields)
 Retrieve realtime configuration.
 
int ast_parse_arg (const char *arg, enum ast_parse_flags flags, void *p_result,...)
 The argument parsing routine.
 
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.
 
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.
 
int ast_realtime_is_mapping_defined (const char *family)
 Determine if a mapping exists for a given family.
 
int ast_realtime_require_field (const char *family,...) attribute_sentinel
 Inform realtime what fields that may be stored.
 
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.
 
int ast_store_realtime_fields (const char *family, const struct ast_variable *fields)
 Create realtime configuration.
 
int ast_unload_realtime (const char *family)
 Release any resources cached for a realtime family.
 
int ast_update2_realtime (const char *family,...) attribute_sentinel
 Update realtime configuration.
 
int ast_update2_realtime_fields (const char *family, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields)
 Update realtime configuration.
 
int ast_update_realtime (const char *family, const char *keyfield, const char *lookup,...) attribute_sentinel
 Update realtime configuration.
 
int ast_update_realtime_fields (const char *family, const char *keyfield, const char *lookup, const struct ast_variable *fields)
 Update realtime configuration.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
int ast_variable_list_replace (struct ast_variable **head, struct ast_variable *replacement)
 Replace a variable in the given list with a new value.
 
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.
 
struct ast_variableast_variable_list_sort (struct ast_variable *head)
 Performs an in-place sort on the variable list by ascending name.
 
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.
 
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.
 
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.
 
void ast_variables_destroy (struct ast_variable *var)
 Free variable list.
 
struct ast_variableast_variables_dup (struct ast_variable *var)
 Duplicate variable list.
 
int ast_variables_match (const struct ast_variable *left, const struct ast_variable *right)
 Tests 2 variable values to see if they match.
 
struct ast_variableast_variables_reverse (struct ast_variable *var)
 Reverse a variable list.
 
int register_config_cli (void)
 Exposed initialization method for core process.
 

Detailed Description

Configuration File Parser.

Definition in file include/asterisk/config.h.

Macro Definition Documentation

◆ ast_category_new_anonymous

#define ast_category_new_anonymous ( )    ast_category_new_dynamic("")

Create a nameless category that is not backed by a file.

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

◆ ast_category_new_dynamic

#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 839 of file include/asterisk/config.h.

◆ ast_config_load

#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 185 of file include/asterisk/config.h.

◆ ast_variable_list_append

#define ast_variable_list_append (   head,
  new_var 
)    ast_variable_list_append_hint(head, NULL, new_var)

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

◆ ast_variable_new

#define ast_variable_new (   name,
  value,
  filename 
)    _ast_variable_new(name, value, filename, __FILE__, __PRETTY_FUNCTION__, __LINE__)

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

◆ CONFIG_RT_NOT_FOUND

#define CONFIG_RT_NOT_FOUND   (void *)-1

Special return value indicating a successful query that returned no data. Used by realtime backends to signal "not found" vs an actual backend failure. This allows the core engine to differentiate and avoid unnecessary failover.

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

◆ CONFIG_STATUS_FILEINVALID

#define CONFIG_STATUS_FILEINVALID   (void *)-2

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

◆ CONFIG_STATUS_FILEMISSING

#define CONFIG_STATUS_FILEMISSING   (void *)0

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

◆ CONFIG_STATUS_FILEUNCHANGED

#define CONFIG_STATUS_FILEUNCHANGED   (void *)-1

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

◆ CV_BOOL

#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

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

◆ CV_DSTR

#define CV_DSTR (   __x,
  __dst 
)    CV_F(__x, ast_free(__dst); __dst = ast_strdup(__val))

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

◆ CV_END

#define CV_END   } while (0)

close a variable parsing block

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

◆ CV_F

#define CV_F (   __pattern,
  __body 
)    if (!strcasecmp((__var), __pattern)) { __body; break; }

call a generic function if the name matches.

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

◆ CV_START

#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 1284 of file include/asterisk/config.h.

1285 { \
1286 const char *__var = __in_var; \
1287 const char *__val = __in_val;

◆ CV_STR

#define CV_STR (   __x,
  __dst 
)    CV_F(__x, ast_copy_string(__dst, __val, sizeof(__dst)))

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

◆ CV_STRFIELD

#define CV_STRFIELD (   __x,
  __obj,
  __field 
)    CV_F(__x, ast_string_field_set(__obj, __field, __val))

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

◆ CV_UINT

#define CV_UINT (   __x,
  __dst 
)    CV_F(__x, (__dst) = strtoul(__val, NULL, 0) )

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

Typedef Documentation

◆ config_hook_cb

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 1120 of file include/asterisk/config.h.

◆ config_load_func

typedef struct ast_config * config_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)

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

◆ realtime_destroy

typedef int realtime_destroy(const char *database, const char *table, const char *keyfield, const char *entity, const struct ast_variable *fields)

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

◆ realtime_multi_get

typedef struct ast_config * realtime_multi_get(const char *database, const char *table, const struct ast_variable *fields)

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

◆ realtime_require

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.

◆ realtime_store

typedef int realtime_store(const char *database, const char *table, const struct ast_variable *fields)

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

◆ realtime_unload

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.

◆ realtime_update

typedef int realtime_update(const char *database, const char *table, const char *keyfield, const char *entity, const struct ast_variable *fields)

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

◆ realtime_update2

typedef int realtime_update2(const char *database, const char *table, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields)

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

◆ realtime_var_get

typedef struct ast_variable * realtime_var_get(const char *database, const char *table, const struct ast_variable *fields)

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

Enumeration Type Documentation

◆ anonymous enum

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. */
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};
@ CONFIG_FLAG_NOCACHE
@ CONFIG_FLAG_NOREALTIME
@ CONFIG_FLAG_WITHCOMMENTS
@ CONFIG_FLAG_FILEUNCHANGED

◆ ast_parse_flags

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.
Enumerator
PARSE_TYPE 
PARSE_INT32 
PARSE_UINT32 
PARSE_DOUBLE 
PARSE_TIMELEN 
PARSE_ADDR 
PARSE_INADDR 
PARSE_DEFAULT 
PARSE_IN_RANGE 
PARSE_OUT_RANGE 
PARSE_RANGE_DEFAULTS 
PARSE_PORT_MASK 
PARSE_PORT_IGNORE 
PARSE_PORT_REQUIRE 
PARSE_PORT_FORBID 

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

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

◆ config_hook_flags

Flags that affect the behaviour of config hooks.

Enumerator
butt 

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

1110 {
1111 butt,
1112};

◆ config_save_flags

Flags for ast_config_text_file_save2()

Enumerator
CONFIG_SAVE_FLAG_NONE 
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 {
54 /*! Insure a context doesn't effectively change if a template changes (pre 13.2 behavior) */
56};
@ CONFIG_SAVE_FLAG_NONE
@ CONFIG_SAVE_FLAG_PRESERVE_EFFECTIVE_CONTEXT

◆ require_type

Types used in ast_realtime_require_field.

Enumerator
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 

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

Function Documentation

◆ _ast_variable_new()

struct ast_variable * _ast_variable_new ( const char *  name,
const char *  value,
const char *  filename,
const char *  file,
const char *  function,
int  lineno 
)

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

316{
317 struct ast_variable *variable;
318 int name_len = strlen(name) + 1;
319 int val_len = strlen(value) + 1;
320 int fn_len = strlen(filename) + 1;
321
322 /* Ensure a minimum length in case the filename is changed later. */
323 if (fn_len < MIN_VARIABLE_FNAME_SPACE) {
325 }
326
327 variable = __ast_calloc(1, fn_len + name_len + val_len + sizeof(*variable),
328 file, lineno, func);
329 if (variable) {
330 char *dst = variable->stuff; /* writable space starts here */
331
332 /* Put file first so ast_include_rename() can calculate space available. */
333 variable->file = strcpy(dst, filename);
334 dst += fn_len;
335 variable->name = strcpy(dst, name);
336 dst += name_len;
337 variable->value = strcpy(dst, value);
338 }
339 return variable;
340}
void * __ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func) attribute_malloc
Definition astmm.c:1603
static const char name[]
Definition format_mp3.c:68
#define MIN_VARIABLE_FNAME_SPACE
Definition main/config.c:74
Structure for variables, used for configurations and for channel variables.
char stuff[0]
Contents of file, name, and value in that order stuffed here.
int value
Definition syslog.c:37

References __ast_calloc(), ast_variable::file, ast_variable::lineno, MIN_VARIABLE_FNAME_SPACE, name, ast_variable::name, ast_variable::stuff, ast_variable::value, and value.

◆ ast_category_append()

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

◆ ast_category_browse()

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 3324 of file extconf.c.

3325{
3326 struct ast_category *cat = NULL;
3327
3328 if (prev && config->last_browse && (config->last_browse->name == prev))
3329 cat = config->last_browse->next;
3330 else if (!prev && config->root)
3331 cat = config->root;
3332 else if (prev) {
3333 for (cat = config->root; cat; cat = cat->next) {
3334 if (cat->name == prev) {
3335 cat = cat->next;
3336 break;
3337 }
3338 }
3339 if (!cat) {
3340 for (cat = config->root; cat; cat = cat->next) {
3341 if (!strcasecmp(cat->name, prev)) {
3342 cat = cat->next;
3343 break;
3344 }
3345 }
3346 }
3347 }
3348
3349 if (cat)
3350 cat = next_available_category(cat);
3351
3352 config->last_browse = cat;
3353 return (cat) ? cat->name : NULL;
3354}
static struct ast_category * next_available_category(struct ast_category *cat)
Definition extconf.c:3317
#define NULL
Definition resample.c:96
char name[80]
struct ast_category * next
struct ast_category * prev

References config, ast_category::name, ast_category::next, next_available_category(), next_available_category(), NULL, ast_category::prev, and ast_category::root.

Referenced by __init_manager(), __queues_show(), ast_cli_perms_init(), AST_TEST_DEFINE(), check_for_old_config(), conf_exec(), find_queue_by_name_rt(), find_realtime(), iax_provision_reload(), internal_process_ast_config(), load_common(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_indications(), load_module(), load_moh_classes(), load_odbc_config(), load_realtime_musiconhold(), load_realtime_queues(), load_realtime_rules(), load_tech_calendars(), load_users(), load_users(), mbl_load_config(), named_acl_find_realtime(), parse_config(), parse_config(), parse_config(), pbx_load_config(), realtime_directory(), realtime_sorcery(), realtime_sorcery_multi(), realtime_switch_common(), reload(), reload_config(), reload_config(), reload_followme(), reload_queue_rules(), reload_queues(), search_directory(), set_config(), set_config(), set_member_value(), setup_dahdi_int(), show_users_realtime(), sla_load_config(), test_config_validity(), update_realtime_members(), and vm_change_password().

◆ ast_category_browse_filtered()

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 1537 of file main/config.c.

1539{
1540 struct ast_category *cat;
1541
1542 if (!prev) {
1543 prev = config->root;
1544 } else {
1545 prev = prev->next;
1546 }
1547
1548 cat = next_available_category(prev, category_name, filter);
1549
1550 return cat;
1551}
static int filter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
static struct ast_category * next_available_category(struct ast_category *cat, const char *name, const char *filter)

References config, filter(), ast_category::next, next_available_category(), ast_category::prev, and ast_category::root.

Referenced by action_getconfig(), action_getconfigjson(), action_listcategories(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), ast_variable_retrieve_filtered(), handle_updates(), object_type_loaded_observer(), sorcery_config_internal_load(), and sorcery_realtime_retrieve_multiple().

◆ ast_category_delete()

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 1696 of file main/config.c.

1698{
1699 struct ast_category *prev;
1700
1701 if (!config || !category) {
1702 return NULL;
1703 }
1704
1705 if (category->prev) {
1706 category->prev->next = category->next;
1707 } else {
1708 config->root = category->next;
1709 }
1710
1711 if (category->next) {
1712 category->next->prev = category->prev;
1713 } else {
1714 config->last = category->prev;
1715 }
1716
1717 prev = category->prev;
1718
1719 if (config->last_browse == category) {
1720 config->last_browse = prev;
1721 }
1722
1723 ast_category_destroy(category);
1724
1725 return prev;
1726}
void ast_category_destroy(struct ast_category *cat)
struct ast_variable * next

References ast_category_destroy(), config, ast_category::last, ast_category::next, NULL, ast_category::prev, and ast_category::root.

Referenced by AST_TEST_DEFINE(), AST_TEST_DEFINE(), handle_updates(), object_type_loaded_observer(), realtime_sorcery_destroy(), and realtime_sorcery_update().

◆ ast_category_destroy()

static void ast_category_destroy ( struct ast_category cat)

◆ ast_category_detach_variables()

struct ast_variable * ast_category_detach_variables ( struct ast_category cat)

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

1554{
1555 struct ast_variable *v;
1556
1557 v = cat->root;
1558 cat->root = NULL;
1559 cat->last = NULL;
1560
1561 return v;
1562}

References ast_category::last, NULL, and ast_category::root.

Referenced by realtime_switch_common(), and sorcery_realtime_retrieve_multiple().

◆ ast_category_empty()

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 1728 of file main/config.c.

1729{
1730 if (!category) {
1731 return -1;
1732 }
1733
1734 ast_variables_destroy(category->root);
1735 category->root = NULL;
1736 category->last = NULL;
1737
1738 return 0;
1739}
void ast_variables_destroy(struct ast_variable *var)
Free variable list.

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

Referenced by AST_TEST_DEFINE(), and handle_updates().

◆ ast_category_exist()

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 1245 of file main/config.c.

1247{
1248 return !!ast_category_get(config, category_name, filter);
1249}
struct ast_category * ast_category_get(const struct ast_config *config, const char *category_name, const char *filter)
Retrieve a category if it exists.

References ast_category_get(), config, and filter().

Referenced by realtime_sorcery_store().

◆ ast_category_first()

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 1359 of file main/config.c.

1360{
1361 return (cat) ? cat->root : NULL;
1362}

References NULL, and ast_category::root.

Referenced by acl_order_comparator(), action_getconfig(), action_getconfigjson(), handle_aor(), handle_auth(), handle_endpoint(), handle_identify(), handle_phoneprov(), handle_registrations(), object_type_loaded_observer(), process_text_line(), sorcery_config_internal_load(), sorcery_is_criteria_met(), sorcery_is_explicit_name_met(), and wizard_apply_handler().

◆ ast_category_get()

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 1206 of file main/config.c.

1208{
1209 return category_get_sep(config, category_name, filter, ',', 1);
1210}
static struct ast_category * category_get_sep(const struct ast_config *config, const char *category_name, const char *filter, char sep, char pointer_match_possible)

References category_get_sep(), config, and filter().

Referenced by add_message_id(), ast_category_exist(), ast_category_root(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), ast_variable_browse(), handle_updates(), object_type_loaded_observer(), realtime_directory(), realtime_sorcery_destroy(), realtime_sorcery_update(), realtime_switch_common(), vm_change_password(), and vm_forwardoptions().

◆ ast_category_get_name()

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 1212 of file main/config.c.

1213{
1214 return category->name;
1215}

References ast_category::name.

Referenced by action_getconfig(), action_getconfigjson(), action_listcategories(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), handle_aor(), handle_auth(), handle_endpoint(), handle_identify(), handle_phoneprov(), handle_registrations(), object_type_loaded_observer(), sorcery_config_internal_load(), and sorcery_is_explicit_name_met().

◆ ast_category_get_templates()

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 1222 of file main/config.c.

1223{
1224 struct ast_category_template_instance *template;
1225 struct ast_str *str;
1226 int first = 1;
1227
1228 if (AST_LIST_EMPTY(&category->template_instances)) {
1229 return NULL;
1230 }
1231
1232 str = ast_str_create(128);
1233 if (!str) {
1234 return NULL;
1235 }
1236
1237 AST_LIST_TRAVERSE(&category->template_instances, template, next) {
1238 ast_str_append(&str, 0, "%s%s", first ? "" : ",", template->name);
1239 first = 0;
1240 }
1241
1242 return str;
1243}
const char * str
Definition app_jack.c:150
struct sla_ringing_trunk * first
Definition app_sla.c:338
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
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_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition strings.h:659
struct ast_category_template_instance * next
struct ast_category::template_instance_list template_instances
Support for dynamic strings.
Definition strings.h:623

References AST_LIST_EMPTY, AST_LIST_TRAVERSE, ast_str_append(), ast_str_create, first, ast_category::next, NULL, str, and ast_category::template_instances.

Referenced by action_getconfig(), and action_getconfigjson().

◆ ast_category_inherit()

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 1569 of file main/config.c.

1570{
1571 struct ast_variable *var;
1573
1574 x = ast_calloc(1, sizeof(*x));
1575 if (!x) {
1576 return -1;
1577 }
1578 strcpy(x->name, base->name);
1579 x->inst = base;
1580 AST_LIST_INSERT_TAIL(&new->template_instances, x, next);
1581 for (var = base->root; var; var = var->next) {
1582 struct ast_variable *cloned = variable_clone(var);
1583 if (!cloned) {
1584 return -1;
1585 }
1586 cloned->inherited = 1;
1587 ast_variable_append(new, cloned);
1588 }
1589 return 0;
1590}
#define var
Definition ast_expr2f.c:605
#define ast_calloc(num, len)
A wrapper for calloc()
Definition astmm.h:202
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
void ast_variable_append(struct ast_category *category, struct ast_variable *variable)
static struct ast_variable * variable_clone(const struct ast_variable *old)
const struct ast_category * inst

References ast_calloc, AST_LIST_INSERT_TAIL, ast_variable_append(), ast_variable::inherited, ast_category_template_instance::inst, ast_category_template_instance::name, ast_category::name, ast_category::next, ast_category::root, var, and variable_clone().

Referenced by handle_updates(), and process_text_line().

◆ ast_category_insert()

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 1267 of file main/config.c.

1268{
1269 struct ast_category *cur_category;
1270
1271 if (!config || !config->root || !cat || !match) {
1272 return -1;
1273 }
1274
1275 if (!strcasecmp(config->root->name, match)) {
1276 cat->next = config->root;
1277 cat->prev = NULL;
1278 config->root->prev = cat;
1279 config->root = cat;
1280 return 0;
1281 }
1282
1283 for (cur_category = config->root->next; cur_category; cur_category = cur_category->next) {
1284 if (!strcasecmp(cur_category->name, match)) {
1285 cat->prev = cur_category->prev;
1286 cat->prev->next = cat;
1287
1288 cat->next = cur_category;
1289 cur_category->prev = cat;
1290
1291 return 0;
1292 }
1293 }
1294
1295 return -1;
1296}
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Definition chan_iax2.c:2388

References config, match(), ast_category::name, ast_variable::next, ast_category::next, NULL, ast_category::prev, and ast_category::root.

Referenced by AST_TEST_DEFINE(), and handle_updates().

◆ ast_category_is_template()

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 1217 of file main/config.c.

1218{
1219 return category->ignored;
1220}

References ast_category::ignored.

Referenced by action_getconfig(), and action_getconfigjson().

◆ ast_category_new()

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 2786 of file extconf.c.

2787{
2788 struct ast_category *category;
2789
2790 if ((category = ast_calloc(1, sizeof(*category))))
2791 ast_copy_string(category->name, name, sizeof(category->name));
2792 category->file = strdup(in_file);
2793 category->lineno = lineno; /* if you don't know the lineno, set it to 999999 or something real big */
2794 return category;
2795}
void ast_copy_string(char *dst, const char *src, size_t size)
Definition extconf.c:968

References ast_calloc, ast_copy_string(), ast_category::file, ast_category::lineno, ast_category::name, name, and new_category().

Referenced by ast_config_copy(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), build_cfg(), handle_updates(), process_text_line(), realtime_sorcery_multi(), realtime_sorcery_store(), realtime_sorcery_update(), and write_password_to_file().

◆ ast_category_new_template()

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 1179 of file main/config.c.

1180{
1181 return new_category(name, in_file, lineno, 1);
1182}
static struct ast_category * new_category(const char *name, const char *in_file, int lineno, int template)

References ast_category::lineno, name, and new_category().

Referenced by AST_TEST_DEFINE(), and handle_updates().

◆ ast_category_rename()

void ast_category_rename ( struct ast_category cat,
const char *  name 
)

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

1565{
1566 ast_copy_string(cat->name, name, sizeof(cat->name));
1567}
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition strings.h:425

References ast_copy_string(), ast_category::name, and name.

Referenced by handle_updates(), realtime_multi_curl(), realtime_multi_ldap(), realtime_multi_mysql(), realtime_multi_odbc(), and realtime_multi_pgsql().

◆ ast_category_root()

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 1364 of file main/config.c.

1365{
1366 struct ast_category *category = ast_category_get(config, cat, NULL);
1367
1368 if (category)
1369 return category->root;
1370 return NULL;
1371}

References ast_category_get(), config, NULL, and ast_category::root.

Referenced by config_function_read(), realtime_sorcery(), and realtime_sorcery_multi().

◆ ast_check_realtime()

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 3797 of file main/config.c.

3798{
3799 struct ast_config_engine *eng;
3800 if (!ast_realtime_enabled()) {
3801 return 0; /* There are no engines at all so fail early */
3802 }
3803
3804 eng = find_engine(family, 1, NULL, 0, NULL, 0);
3805 if (eng)
3806 return 1;
3807 return 0;
3808}
int ast_realtime_enabled(void)
Check if there's any realtime engines loaded.
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.
Configuration engine structure, used to define realtime drivers.

References ast_realtime_enabled(), find_engine(), and NULL.

Referenced by __queues_show(), ast_named_acl_find(), ast_queue_log(), close_mailbox(), copy_plain_file(), handle_voicemail_show_users(), leave_voicemail(), load_module(), load_moh_classes(), load_realtime_queues(), load_realtime_rules(), local_ast_moh_start(), logger_queue_rt_start(), manager_queues_status(), manager_queues_summary(), msg_create_from_file(), rename_file(), set_member_paused(), set_member_value(), and vm_delete().

◆ ast_config_copy()

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 3501 of file main/config.c.

3502{
3503 struct ast_config *new_config = ast_config_new();
3504 struct ast_category *cat_iter;
3505
3506 if (!new_config) {
3507 return NULL;
3508 }
3509
3510 for (cat_iter = old->root; cat_iter; cat_iter = cat_iter->next) {
3511 struct ast_category *new_cat =
3512 ast_category_new(cat_iter->name, cat_iter->file, cat_iter->lineno);
3513 if (!new_cat) {
3514 goto fail;
3515 }
3516 ast_category_append(new_config, new_cat);
3517 if (cat_iter->root) {
3518 new_cat->root = ast_variables_dup(cat_iter->root);
3519 if (!new_cat->root) {
3520 goto fail;
3521 }
3522 new_cat->last = cat_iter->last;
3523 }
3524 }
3525
3526 return new_config;
3527
3528fail:
3529 ast_config_destroy(new_config);
3530 return NULL;
3531}
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
struct ast_config * ast_config_new(void)
Create a new base configuration structure.
struct ast_category * ast_category_new(const char *name, const char *in_file, int lineno)
Create a category.
void ast_category_append(struct ast_config *config, struct ast_category *category)
Appends a category to a config.
struct ast_variable * ast_variables_dup(struct ast_variable *var)
Duplicate variable list.

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

Referenced by AST_TEST_DEFINE(), and config_hook_exec().

◆ ast_config_destroy()

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 1287 of file extconf.c.

1288{
1289 struct ast_category *cat, *catn;
1290
1291 if (!cfg)
1292 return;
1293
1295
1296 cat = cfg->root;
1297 while (cat) {
1299 catn = cat;
1300 cat = cat->next;
1301 free(catn);
1302 }
1303 free(cfg);
1304}
static void ast_includes_destroy(struct ast_config_include *incls)
Definition extconf.c:1271
struct ast_config_include * includes
Definition extconf.c:916
struct ast_category * root

References ast_category_destroy(), ast_free, ast_includes_destroy(), ast_includes_destroy(), ast_variables_destroy(), free(), ast_config::includes, ast_config::includes_root, ast_category::next, ast_category::root, and ast_config::root.

Referenced by __ast_http_load(), __ast_http_post_load(), __ast_sorcery_apply_config(), __init_manager(), __queues_show(), _dsp_init(), aco_process_config(), action_getconfig(), action_getconfigjson(), action_listcategories(), action_updateconfig(), adsi_load(), advanced_options(), ast_cli_perms_init(), ast_config_copy(), ast_config_load2(), ast_init_logger_for_socket_console(), ast_load_realtime_multientry_fields(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), build_cfg(), check_for_old_config(), conf_exec(), config_function_read(), config_module(), deinitialize_sorcery(), directory_exec(), do_reload(), festival_exec(), find_conf(), find_load_queue_rt_friendly(), find_realtime(), forward_message(), get_defaults(), handle_cli_dialplan_save(), hook_cb(), iax_provision_reload(), init_logger_chain(), initialize_cc_devstate_map(), initialize_cc_max_requests(), load_asterisk_conf(), load_common(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config_force(), load_config_meetme(), load_indications(), load_module(), load_module(), load_module(), load_module(), load_module(), load_module(), load_module(), load_moh_classes(), load_odbc_config(), load_realtime_musiconhold(), load_realtime_queues(), load_realtime_rules(), load_users(), loader_config_init(), make_email_file(), mbl_load_config(), message_range_and_existence_check(), my_load_module(), named_acl_find_realtime(), notify_new_message(), object_type_loaded_observer(), odbc_load_module(), parse_config(), parse_config(), parse_config(), parse_config(), parse_config(), parse_general_options(), pbx_load_config(), play_message(), prep_email_sub_vars(), private_enum_init(), process_config(), process_config(), read_password_from_file(), read_pjproject_startup_options(), realtime_directory(), realtime_multi_mysql(), realtime_multi_pgsql(), realtime_sorcery_multi(), realtime_sqlite3_multi(), realtime_switch_common(), reload(), reload(), reload_config(), reload_config(), reload_followme(), reload_module(), reload_module(), reload_module(), reload_queue_rules(), reload_queues(), rtp_reload(), run_startup_commands(), set_config(), set_config(), set_config(), set_member_value(), setup_dahdi_int(), show_users_realtime(), sla_load_config(), smdi_load(), sorcery_config_internal_load(), sorcery_realtime_retrieve_multiple(), tds_load_module(), tds_load_module(), unload_module(), unload_module(), unload_module(), update_realtime_members(), vm_change_password(), vm_forwardoptions(), vm_msg_forward(), vm_msg_play(), vm_msg_snapshot_create(), write_password_to_file(), and xmldoc_load_documentation().

◆ ast_config_engine_deregister()

int ast_config_engine_deregister ( struct ast_config_engine del)

Deregister config engine.

Return values
0Always

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

3429{
3430 struct ast_config_engine *ptr, *last=NULL;
3431
3433
3434 for (ptr = config_engine_list; ptr; ptr=ptr->next) {
3435 if (ptr == del) {
3436 if (last)
3437 last->next = ptr->next;
3438 else
3439 config_engine_list = ptr->next;
3440 break;
3441 }
3442 last = ptr;
3443 }
3444
3445 return 0;
3446}
ast_mutex_t lock
Definition app_sla.c:337
struct sla_ringing_trunk * last
Definition app_sla.c:338
#define SCOPED_MUTEX(varname, lock)
scoped lock specialization for mutexes
Definition lock.h:596
static ast_mutex_t config_lock
static struct ast_config_engine * config_engine_list
struct ast_config_engine * next
struct sla_ringing_trunk * next
Definition app_sla.c:314

References config_engine_list, config_lock, last, lock, sla_ringing_trunk::next, ast_config_engine::next, NULL, and SCOPED_MUTEX.

Referenced by unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), and unload_module().

◆ ast_config_engine_register()

int ast_config_engine_register ( struct ast_config_engine newconfig)

Register config engine.

Return values
1Always

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

3413{
3414 struct ast_config_engine *ptr;
3415
3417
3418 if (!config_engine_list) {
3419 config_engine_list = new;
3420 } else {
3421 for (ptr = config_engine_list; ptr->next; ptr=ptr->next);
3422 ptr->next = new;
3423 }
3424
3425 return 1;
3426}

References config_engine_list, config_lock, lock, ast_config_engine::next, and SCOPED_MUTEX.

Referenced by load_module(), load_module(), load_module(), load_module(), load_module(), load_module(), and load_module().

◆ ast_config_get_current_category()

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 2779 of file extconf.c.

2780{
2781 return cfg->current;
2782}
struct ast_category * current

References ast_config::current.

Referenced by config_curl(), config_odbc(), config_text_file_load(), and config_text_file_load().

◆ ast_config_hook_register()

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 4569 of file main/config.c.

4574{
4575 struct cfg_hook *hook;
4576 if (!cfg_hooks) {
4579 if (!cfg_hooks) {
4580 return -1;
4581 }
4582 }
4583
4584 if (!(hook = ao2_alloc(sizeof(*hook), hook_destroy))) {
4585 return -1;
4586 }
4587
4588 hook->hook_cb = hook_cb;
4589 hook->filename = ast_strdup(filename);
4590 hook->name = ast_strdup(name);
4591 hook->module = ast_strdup(module);
4592
4593 ao2_link(cfg_hooks, hook);
4594 ao2_ref(hook, -1);
4595 return 0;
4596}
#define ast_strdup(str)
A wrapper for strdup()
Definition astmm.h:241
#define ao2_link(container, obj)
Add an object to a container.
Definition astobj2.h:1532
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition astobj2.h:363
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition astobj2.h:459
#define ao2_alloc(data_size, destructor_fn)
Definition astobj2.h:409
#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
static int hook_hash(const void *obj, const int flags)
static struct ao2_container * cfg_hooks
Definition main/config.c:78
static void hook_destroy(void *obj)
static int hook_cmp(void *obj, void *arg, int flags)
const char * filename
const char * name
const char *config_hook_cb hook_cb
static int hook_cb(struct ast_config *cfg)

References ao2_alloc, AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ao2_link, ao2_ref, ast_strdup, cfg_hooks, cfg_hook::filename, cfg_hook::hook_cb, hook_cb(), hook_cmp(), hook_destroy(), hook_hash(), name, cfg_hook::name, and NULL.

Referenced by AST_TEST_DEFINE().

◆ ast_config_hook_unregister()

void ast_config_hook_unregister ( const char *  name)

Unregister a config hook.

Parameters
nameThe name of the hook to unregister

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

4542{
4543 struct cfg_hook tmp;
4544
4545 tmp.name = ast_strdupa(name);
4546
4548}
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition astmm.h:298
#define OBJ_POINTER
Definition astobj2.h:1150
#define ao2_find(container, arg, flags)
Definition astobj2.h:1736
@ OBJ_NODATA
Definition astobj2.h:1044
@ OBJ_UNLINK
Definition astobj2.h:1039

References ao2_find, ast_strdupa, cfg_hooks, name, cfg_hook::name, OBJ_NODATA, OBJ_POINTER, and OBJ_UNLINK.

Referenced by AST_TEST_DEFINE().

◆ ast_config_internal_load()

struct ast_config * ast_config_internal_load ( const char *  configfile,
struct ast_config cfg,
struct ast_flags  flags,
const char *  suggested_incl_file,
const char *  who_asked 
)

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

3535{
3536 char db[256];
3537 char table[256];
3538 struct ast_config_engine *loader = &text_file_engine;
3539 struct ast_config *result;
3540
3541 /* The config file itself bumps include_level by 1 */
3542 if (cfg->max_include_level > 0 && cfg->include_level == cfg->max_include_level + 1) {
3543 ast_log(LOG_WARNING, "Maximum Include level (%d) exceeded\n", cfg->max_include_level);
3544 return NULL;
3545 }
3546
3547 cfg->include_level++;
3548
3550 struct ast_config_engine *eng;
3551
3552 eng = find_engine(filename, 1, db, sizeof(db), table, sizeof(table));
3553
3554
3555 if (eng && eng->load_func) {
3556 loader = eng;
3557 } else {
3558 eng = find_engine("global", 1, db, sizeof(db), table, sizeof(table));
3559 if (eng && eng->load_func)
3560 loader = eng;
3561 }
3562 }
3563
3564 result = loader->load_func(db, table, filename, cfg, flags, suggested_include_file, who_asked);
3565
3567 result->include_level--;
3568 config_hook_exec(filename, who_asked, result);
3569 } else if (result != CONFIG_STATUS_FILEINVALID) {
3570 cfg->include_level--;
3571 }
3572
3573 return result;
3574}
#define ast_log
Definition astobj2.c:42
static sqlite3 * db
static PGresult * result
Definition cel_pgsql.c:84
#define CONFIG_STATUS_FILEUNCHANGED
#define CONFIG_STATUS_FILEINVALID
#define LOG_WARNING
static void config_hook_exec(const char *filename, const char *module, const struct ast_config *cfg)
static struct ast_config_engine text_file_engine
config_load_func * load_func
int include_level
int max_include_level
#define ast_test_flag(p, flag)
Definition utils.h:63

References ast_log, ast_test_flag, config_engine_list, CONFIG_FLAG_NOREALTIME, config_hook_exec(), CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, db, find_engine(), ast_config::include_level, ast_config_engine::load_func, LOG_WARNING, ast_config::max_include_level, NULL, result, and text_file_engine.

Referenced by ast_config_load2(), config_curl(), config_ldap(), config_mysql(), config_odbc(), config_pgsql(), process_text_line(), reload_module(), and static_realtime_cb().

◆ ast_config_load2()

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 3576 of file main/config.c.

3577{
3578 struct ast_config *cfg;
3579 struct ast_config *result;
3580
3581 cfg = ast_config_new();
3582 if (!cfg)
3583 return NULL;
3584
3585 result = ast_config_internal_load(filename, cfg, flags, "", who_asked);
3587 ast_config_destroy(cfg);
3588
3589 return result;
3590}
struct ast_config * ast_config_internal_load(const char *filename, struct ast_config *cfg, struct ast_flags flags, const char *suggested_include_file, const char *who_asked)

References ast_config_destroy(), ast_config_internal_load(), ast_config_new(), CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, NULL, and result.

Referenced by __ast_http_load(), __ast_http_post_load(), __ast_sorcery_apply_config(), __init_manager(), _dsp_init(), action_getconfig(), action_getconfigjson(), action_listcategories(), action_updateconfig(), ast_cli_perms_init(), ast_init_logger_for_socket_console(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), do_reload(), iax_provision_reload(), init_logger_chain(), initialize_cc_devstate_map(), initialize_cc_max_requests(), load_asterisk_conf(), load_config(), load_config(), load_indications(), loader_config_init(), object_type_loaded_observer(), parse_general_options(), private_enum_init(), read_pjproject_startup_options(), rtp_reload(), run_startup_commands(), set_config(), sorcery_config_internal_load(), and xmldoc_load_documentation().

◆ ast_config_new()

static struct ast_config * ast_config_new ( void  )

◆ ast_config_option()

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 860 of file main/config.c.

861{
862 const char *tmp;
863 tmp = ast_variable_retrieve(cfg, cat, var);
864 if (!tmp) {
865 tmp = ast_variable_retrieve(cfg, "general", var);
866 }
867 return tmp;
868}
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)

References ast_variable_retrieve(), and var.

Referenced by process_config(), and process_config().

◆ ast_config_set_current_category()

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 3360 of file extconf.c.

3361{
3362 /* cast below is just to silence compiler warning about dropping "const" */
3363 cfg->current = (struct ast_category *) cat;
3364}

References ast_config::current.

Referenced by process_text_line().

◆ ast_config_sort_categories()

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 1373 of file main/config.c.

1375{
1376 /*
1377 * The contents of this function are adapted from
1378 * an example of linked list merge sorting
1379 * copyright 2001 Simon Tatham.
1380 *
1381 * Permission is hereby granted, free of charge, to any person
1382 * obtaining a copy of this software and associated documentation
1383 * files (the "Software"), to deal in the Software without
1384 * restriction, including without limitation the rights to use,
1385 * copy, modify, merge, publish, distribute, sublicense, and/or
1386 * sell copies of the Software, and to permit persons to whom the
1387 * Software is furnished to do so, subject to the following
1388 * conditions:
1389 *
1390 * The above copyright notice and this permission notice shall be
1391 * included in all copies or substantial portions of the Software.
1392 *
1393 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1394 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
1395 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1396 * NONINFRINGEMENT. IN NO EVENT SHALL SIMON TATHAM BE LIABLE FOR
1397 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
1398 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1399 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1400 * SOFTWARE.
1401 */
1402
1403 int insize = 1;
1404 struct ast_category *p, *q, *e, *tail;
1405 int nmerges, psize, qsize, i;
1406
1407 /* If the descending flag was sent, we'll apply inversion to the comparison function's return. */
1408 if (descending) {
1409 descending = -1;
1410 } else {
1411 descending = 1;
1412 }
1413
1414 if (!config->root) {
1415 return;
1416 }
1417
1418 while (1) {
1419 p = config->root;
1420 config->root = NULL;
1421 tail = NULL;
1422
1423 nmerges = 0; /* count number of merges we do in this pass */
1424
1425 while (p) {
1426 nmerges++; /* there exists a merge to be done */
1427
1428 /* step `insize' places along from p */
1429 q = p;
1430 psize = 0;
1431 for (i = 0; i < insize; i++) {
1432 psize++;
1433 q = q->next;
1434 if (!q) {
1435 break;
1436 }
1437 }
1438
1439 /* if q hasn't fallen off end, we have two lists to merge */
1440 qsize = insize;
1441
1442 /* now we have two lists; merge them */
1443 while (psize > 0 || (qsize > 0 && q)) {
1444 /* decide whether next element of merge comes from p or q */
1445 if (psize == 0) {
1446 /* p is empty; e must come from q. */
1447 e = q;
1448 q = q->next;
1449 qsize--;
1450 } else if (qsize == 0 || !q) {
1451 /* q is empty; e must come from p. */
1452 e = p; p = p->next; psize--;
1453 } else if ((comparator(p, q) * descending) <= 0) {
1454 /* First element of p is lower (or same) e must come from p. */
1455 e = p;
1456 p = p->next;
1457 psize--;
1458 } else {
1459 /* First element of q is lower; e must come from q. */
1460 e = q;
1461 q = q->next;
1462 qsize--;
1463 }
1464
1465 /* add the next element to the merged list */
1466 if (tail) {
1467 tail->next = e;
1468 } else {
1469 config->root = e;
1470 }
1471 tail = e;
1472 }
1473
1474 /* now p has stepped `insize' places along, and q has too */
1475 p = q;
1476 }
1477
1478 tail->next = NULL;
1479
1480 /* If we have done only one merge, we're finished. */
1481 if (nmerges <= 1) { /* allow for nmerges==0, the empty list case */
1482 return;
1483 }
1484
1485 /* Otherwise repeat, merging lists twice the size */
1486 insize *= 2;
1487 }
1488
1489}

References config, ast_category::next, NULL, and ast_category::root.

Referenced by named_acl_find_realtime(), and realtime_switch_common().

◆ ast_config_text_file_save()

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 2870 of file main/config.c.

2871{
2873}
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.

References ast_config_text_file_save2(), and CONFIG_SAVE_FLAG_PRESERVE_EFFECTIVE_CONTEXT.

Referenced by add_message_id(), AST_TEST_DEFINE(), vm_change_password(), vm_forwardoptions(), and write_password_to_file().

◆ ast_config_text_file_save2()

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 2929 of file main/config.c.

2930{
2931 FILE *f;
2932 char fn[PATH_MAX];
2933 struct ast_variable *var;
2934 struct ast_category *cat;
2935 struct ast_comment *cmt;
2936 struct ast_config_include *incl;
2937 int blanklines = 0;
2938 struct ao2_container *fileset;
2939 struct inclfile *fi;
2940
2941 /* Check all the files for write access before attempting to modify any of them */
2942 for (incl = cfg->includes_root; incl; incl = incl->next) {
2943 /* reset all the output flags in case this isn't our first time saving this data */
2944 incl->output = 0;
2945
2946 if (incl->include_type != CONFIG_STATEMENT_EXEC) {
2947 struct config_included_file *included_file;
2948 int ok = 1;
2949
2950 /* Not a #exec. */
2951 /* For #include, make sure we have write access to the include file
2952 file or its parent directory. If the file itself doesn't exist,
2953 make sure we have write access to the directory. */
2954 /* For #tryinclude, we check the file(s) that match the pattern. */
2955
2956 AST_LIST_TRAVERSE(&incl->included_files, included_file, next) {
2957 if (!is_writable(included_file->path)) {
2958 /* the #tryinclude path exists but is not writable */
2959 ok = 0;
2960 break;
2961 }
2962 }
2963
2964 if (!ok) {
2965 /* at least one include file is not writable */
2966 return -1;
2967 }
2968 }
2969 }
2970
2971 /* now make sure we have write access to the main config file or its parent directory */
2972 make_fn(fn, sizeof(fn), 0, configfile);
2973 if (!is_writable(fn)) {
2974 return -1;
2975 }
2976
2979 if (!fileset) {
2980 /* Container creation failed. */
2981 return -1;
2982 }
2983
2984 /* Now that we know we have write access to all files, it's safe to start truncating them */
2985
2986 /* go thru all the inclusions and make sure all the files involved (configfile plus all its inclusions)
2987 are all truncated to zero bytes and have that nice header*/
2988 /* Note: for #exec, we write out the directives but don't zero out the exec files */
2989 for (incl = cfg->includes_root; incl; incl = incl->next) {
2990 if (incl->include_type != CONFIG_STATEMENT_EXEC) {
2991 struct config_included_file *included_file;
2992
2993 AST_LIST_TRAVERSE(&incl->included_files, included_file, next) {
2994 fi = set_fn(fn, sizeof(fn), included_file->path, configfile, fileset);
2995 f = fopen(fn, "w");
2996 if (f) {
2997 ast_verb(2, "Saving tryinclude '%s'\n", fn);
2998 gen_header(f, configfile, fn, generator);
2999 fclose(f);
3000 } else {
3001 ast_log(LOG_ERROR, "Unable to write %s (%s)\n", fn, strerror(errno));
3002 }
3003 if (fi) {
3004 ao2_ref(fi, -1);
3005 }
3006 }
3007 }
3008 }
3009
3010 /* just set fn to absolute ver of configfile */
3011 fi = set_fn(fn, sizeof(fn), 0, configfile, fileset);
3012 if (
3013#ifdef __CYGWIN__
3014 (f = fopen(fn, "w+"))
3015#else
3016 (f = fopen(fn, "w"))
3017#endif
3018 ) {
3019 ast_verb(2, "Saving '%s'\n", fn);
3020 gen_header(f, configfile, fn, generator);
3021 cat = cfg->root;
3022 fclose(f);
3023 if (fi) {
3024 ao2_ref(fi, -1);
3025 }
3026
3027 /* from here out, we open each involved file and concat the stuff we need to add to the end and immediately close... */
3028 /* since each var, cat, and associated comments can come from any file, we have to be
3029 mobile, and open each file, print, and close it on an entry-by-entry basis */
3030
3031 while (cat) {
3032 fi = set_fn(fn, sizeof(fn), cat->file, configfile, fileset);
3033 f = fopen(fn, "a");
3034 if (!f) {
3035 ast_log(LOG_ERROR, "Unable to write %s (%s)\n", fn, strerror(errno));
3036 if (fi) {
3037 ao2_ref(fi, -1);
3038 }
3039 ao2_ref(fileset, -1);
3040 return -1;
3041 }
3042
3043 /* dump any includes that happen before this category header */
3044 for (incl = cfg->includes_root; incl; incl = incl->next) {
3045 if (strcmp(incl->include_location_file, cat->file) == 0) {
3046 if (cat->lineno > incl->include_location_lineno && !incl->output) {
3047 /* add the precomments */
3049 print_comment(f, incl->precomments);
3050 /* and the include */
3051 print_include(f, incl);
3052 incl->output = 1;
3053 }
3054 }
3055 }
3056
3057 /* dump any comments that happen before this category header */
3059 print_comment(f, cat->precomments);
3060
3061 /* dump the category header */
3062 fprintf(f, "[%s]", cat->name);
3063 if (cat->ignored || !AST_LIST_EMPTY(&cat->template_instances)) {
3064 fprintf(f, "(");
3065 if (cat->ignored) {
3066 fprintf(f, "!");
3067 }
3068 if (cat->ignored && !AST_LIST_EMPTY(&cat->template_instances)) {
3069 fprintf(f, ",");
3070 }
3071 if (!AST_LIST_EMPTY(&cat->template_instances)) {
3074 fprintf(f, "%s",x->name);
3075 if (x != AST_LIST_LAST(&cat->template_instances))
3076 fprintf(f, ",");
3077 }
3078 }
3079 fprintf(f, ")");
3080 }
3081 for(cmt = cat->sameline; cmt; cmt = cmt->next)
3082 {
3083 fprintf(f, "%s", cmt->cmt);
3084 }
3085 if (!cat->sameline)
3086 fprintf(f, "\n");
3087
3088 /* dump any trailing comments */
3089 print_comment(f, cat->trailing);
3090
3091 /* and we're all done */
3092 fclose(f);
3093 if (fi) {
3094 ao2_ref(fi, -1);
3095 }
3096
3097 var = cat->root;
3098 while (var) {
3100 struct ast_variable *parent = NULL; /* last occurrence matching variable name */
3101
3102 /*
3103 * When saving the configuration we have the option to preserve
3104 * the effective category contents. If enabled, the template
3105 * variables are materialized into the leaf categories. Here,
3106 * we check to see if a variable is also present in the leaf
3107 * and, if so, we do not keep just the leaf value (no point in
3108 * duplicate "var = value" lines in the .conf.
3109 */
3111 if (var->inherited) {
3112 struct ast_variable *v;
3113 int skip = 0;
3114
3115 for (v = var->next; v; v = v->next) {
3116 if (!strcasecmp(var->name, v->name)) {
3117 /* skip earlier inherited duplicate */
3118 skip = 1;
3119 break;
3120 }
3121 }
3122 if (skip) {
3123 var = var->next;
3124 continue;
3125 }
3126 }
3127 }
3128
3129 /*
3130 * Walk every template instance in the order Asterisk applies
3131 * them, letting later templates override earlier ones.
3132 */
3134 struct ast_variable *v;
3135 struct ast_variable *last = NULL;
3136
3137 /* Within a template, capture the last occurrence of the key. */
3138 for (v = x->inst->root; v; v = v->next) {
3139 if (!strcasecmp(var->name, v->name)) {
3140 last = v;
3141 }
3142 }
3143
3144 if (last) {
3145 parent = last;
3146 }
3147 }
3148
3149 /* decide whether to write the variable */
3151 /* materialize inherited vars; suppress only explicit exact dups */
3152 if (!var->inherited && parent && !strcmp(var->value, parent->value)) {
3153 var = var->next;
3154 continue;
3155 }
3156 } else {
3157 /* skip inherited, explicit exact dups */
3158 if (var->inherited || (parent && !strcmp(var->value, parent->value))) {
3159 var = var->next;
3160 continue;
3161 }
3162 }
3163
3164 fi = set_fn(fn, sizeof(fn), var->file, configfile, fileset);
3165 f = fopen(fn, "a");
3166 if (!f) {
3167 ast_debug(1, "Unable to open for writing: %s\n", fn);
3168 ast_verb(2, "Unable to write %s (%s)\n", fn, strerror(errno));
3169 if (fi) {
3170 ao2_ref(fi, -1);
3171 }
3172 ao2_ref(fileset, -1);
3173 return -1;
3174 }
3175
3176 /* dump any includes that happen before this variable */
3177 for (incl = cfg->includes_root; incl; incl = incl->next) {
3178 if (strcmp(incl->include_location_file, var->file) == 0) {
3179 if (var->lineno > incl->include_location_lineno && !incl->output) {
3180 /* add the precomments */
3182 print_comment(f, incl->precomments);
3183 /* and the include */
3184 print_include(f, incl);
3185 incl->output = 1;
3186 }
3187 }
3188 }
3189
3190 /* dump any comments that happen before this variable */
3191 insert_leading_blank_lines(f, fi, var->precomments, var->lineno);
3192 print_comment(f, var->precomments);
3193
3194 { /* Block for 'escaped' scope */
3195 int escaped_len = 2 * strlen(var->value) + 1;
3196 char escaped[escaped_len];
3197
3198 ast_escape_semicolons(var->value, escaped, escaped_len);
3199
3200 if (var->sameline) {
3201 fprintf(f, "%s %s %s %s", var->name, (var->object ? "=>" : "="),
3202 escaped, var->sameline->cmt);
3203 } else {
3204 fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="),
3205 escaped);
3206 }
3207 }
3208
3209 /* dump any trailing comments */
3210 print_comment(f, var->trailing);
3211 if (var->blanklines) {
3212 blanklines = var->blanklines;
3213 while (blanklines--)
3214 fprintf(f, "\n");
3215 }
3216
3217 fclose(f);
3218 if (fi) {
3219 ao2_ref(fi, -1);
3220 }
3221
3222 var = var->next;
3223 }
3224 cat = cat->next;
3225 }
3226
3227
3228 /* Now, for files with trailing #include/#exec statements,
3229 we have to make sure every entry is output */
3230 for (incl = cfg->includes_root; incl; incl = incl->next) {
3231 if (!incl->output) {
3232 /* open the respective file */
3233 fi = set_fn(fn, sizeof(fn), incl->include_location_file, configfile, fileset);
3234 f = fopen(fn, "a");
3235 if (!f) {
3236 ast_debug(1, "Unable to open for writing: %s\n", fn);
3237 ast_verb(2, "Unable to write %s (%s)\n", fn, strerror(errno));
3238 if (fi) {
3239 ao2_ref(fi, -1);
3240 }
3241 ao2_ref(fileset, -1);
3242 return -1;
3243 }
3244
3245 /* add the precomments */
3247 print_comment(f, incl->precomments);
3248 /* and the include */
3249 print_include(f, incl);
3250 /* and any trailing comments */
3251 print_comment(f, incl->trailing);
3252
3253 incl->output = 1;
3254 fclose(f);
3255 if (fi) {
3256 ao2_ref(fi, -1);
3257 }
3258 }
3259 }
3260
3261
3262 ast_verb(2, "Saving '%s': saved\n", fn);
3263 } else {
3264 ast_debug(1, "Unable to open for writing: %s\n", fn);
3265 ast_verb(2, "Unable to write '%s' (%s)\n", fn, strerror(errno));
3266 if (fi) {
3267 ao2_ref(fi, -1);
3268 }
3269 ao2_ref(fileset, -1);
3270 return -1;
3271 }
3272
3273 ao2_ref(fileset, -1); /* this should destroy the hash container */
3274
3275 /* pass new configuration to any config hooks */
3276 config_hook_exec(configfile, generator, cfg);
3277
3278 return 0;
3279}
#define PATH_MAX
Definition asterisk.h:40
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
#define ast_verb(level,...)
#define AST_LIST_LAST(head)
Returns the last entry contained in a list.
@ CONFIG_STATEMENT_EXEC
static void insert_leading_blank_lines(FILE *fp, struct inclfile *fi, struct ast_comment *precomments, int lineno)
static int hashtab_compare_strings(void *a, void *b, int flags)
static void gen_header(FILE *f1, const char *configfile, const char *fn, const char *generator)
static void print_include(FILE *f, struct ast_config_include *incl)
static int hash_string(const void *obj, const int flags)
static struct inclfile * set_fn(char *fn, size_t fn_size, const char *file, const char *configfile, struct ao2_container *fileset)
static void print_comment(FILE *f, struct ast_comment *comment)
static int is_writable(const char *fn)
static void make_fn(char *fn, size_t fn_size, const char *file, const char *configfile)
int errno
Generic container type.
struct ast_comment * precomments
struct ast_comment * trailing
struct ast_comment * sameline
Structure to keep comments for rewriting configuration files.
Definition main/config.c:85
char cmt[0]
Definition main/config.c:88
struct ast_comment * next
Definition main/config.c:86
char * include_location_file
file name in which the include occurs
struct ast_config_include::included_files_list included_files
struct ast_config_include * next
struct ast_comment * precomments
enum include_statement_type include_type
struct ast_comment * trailing
struct ast_config_include * includes_root
struct ast_comment * sameline
struct config_included_file * next
char * ast_escape_semicolons(const char *string, char *outbuf, int buflen)
Escape semicolons found in a string.
Definition utils.c:847

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_log, ast_verb, ast_comment::cmt, config_hook_exec(), CONFIG_SAVE_FLAG_PRESERVE_EFFECTIVE_CONTEXT, CONFIG_STATEMENT_EXEC, errno, ast_category::file, gen_header(), hash_string(), hashtab_compare_strings(), ast_category::ignored, ast_config_include::include_location_file, ast_config_include::include_location_lineno, ast_config_include::include_type, ast_config_include::included_files, ast_config::includes_root, insert_leading_blank_lines(), ast_category_template_instance::inst, is_writable(), last, inclfile::lineno, ast_category::lineno, ast_category::loaded, LOG_ERROR, make_fn(), ast_variable::name, ast_category_template_instance::name, ast_category::name, sla_ringing_trunk::next, ast_variable::next, ast_comment::next, ast_category::next, ast_config_include::next, NULL, ast_config_include::output, config_included_file::path, PATH_MAX, ast_category::precomments, ast_config_include::precomments, print_comment(), print_include(), ast_category::root, ast_config::root, ast_category::sameline, set_fn(), ast_category::template_instances, ast_category::trailing, ast_config_include::trailing, ast_variable::value, and var.

Referenced by action_updateconfig(), and ast_config_text_file_save().

◆ ast_destroy_realtime()

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 4043 of file main/config.c.

4044{
4045 RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
4046 int res = 0;
4047 va_list ap;
4048
4049 va_start(ap, lookup);
4050 if (realtime_arguments_to_fields(ap, &fields)) {
4051 res = -1;
4052 }
4053 va_end(ap);
4054
4055 if (res) {
4056 return -1;
4057 }
4058
4059 return ast_destroy_realtime_fields(family, keyfield, lookup, fields);
4060}
int ast_destroy_realtime_fields(const char *family, const char *keyfield, const char *lookup, const struct ast_variable *fields)
Destroy realtime configuration.
#define realtime_arguments_to_fields(ap, result)
#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:978

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

Referenced by cli_realtime_destroy(), function_realtime_readdestroy(), leave_voicemail(), msg_create_from_file(), and vm_delete().

◆ ast_destroy_realtime_fields()

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 4023 of file main/config.c.

4024{
4025 struct ast_config_engine *eng;
4026 int res = -1, i;
4027 char db[256];
4028 char table[256];
4029
4030 for (i = 1; ; i++) {
4031 if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
4032 if (eng->destroy_func && ((res = eng->destroy_func(db, table, keyfield, lookup, fields)) >= 0)) {
4033 break;
4034 }
4035 } else {
4036 break;
4037 }
4038 }
4039
4040 return res;
4041}
realtime_destroy * destroy_func

References db, ast_config_engine::destroy_func, and find_engine().

Referenced by ast_destroy_realtime(), and sorcery_realtime_delete().

◆ ast_include_find()

static struct ast_config_include * ast_include_find ( struct ast_config conf,
const char *  included_file 
)

Definition at line 1161 of file extconf.c.

1162{
1163 struct ast_config_include *x;
1164 for (x=conf->includes;x;x=x->next)
1165 {
1166 if (strcmp(x->included_file,included_file) == 0)
1167 return x;
1168 }
1169 return 0;
1170}
char * included_file
file name included
All configuration options for http media cache.

References ast_config_include::included_file, and ast_config_include::next.

Referenced by ast_include_new().

◆ ast_include_new()

static struct ast_config_include * ast_include_new ( struct ast_config conf,
const char *  from_file,
const char *  included_file,
int  include_type,
const char *  exec_file,
int  from_lineno,
char *  real_included_file_name,
int  real_included_file_name_size 
)

Definition at line 1072 of file extconf.c.

1073{
1074 /* a file should be included ONCE. Otherwise, if one of the instances is changed,
1075 then all be changed. -- how do we know to include it? -- Handling modified
1076 instances is possible, I'd have
1077 to create a new master for each instance. */
1078 struct ast_config_include *inc;
1079
1081 if (inc)
1082 {
1083 inc->inclusion_count++;
1084 snprintf(real_included_file_name, real_included_file_name_size, "%s~~%d", included_file, inc->inclusion_count);
1085 ast_log(LOG_WARNING,"'%s', line %d: Same File included more than once! This data will be saved in %s if saved back to disk.\n", from_file, from_lineno, real_included_file_name);
1086 } else
1087 *real_included_file_name = 0;
1088
1089 inc = ast_calloc(1,sizeof(struct ast_config_include));
1090 inc->include_location_file = ast_strdup(from_file);
1091 inc->include_location_lineno = from_lineno;
1092 if (!ast_strlen_zero(real_included_file_name))
1093 inc->included_file = ast_strdup(real_included_file_name);
1094 else
1096
1097 inc->exec = is_exec;
1098 if (is_exec)
1100
1101 /* attach this new struct to the conf struct */
1102 inc->next = conf->includes;
1103 conf->includes = inc;
1104
1105 return inc;
1106}
static struct ast_config_include * ast_include_find(struct ast_config *conf, const char *included_file)
Definition extconf.c:1161
#define LOG_WARNING
Definition extconf.c:139
static force_inline int ast_strlen_zero(const char *s)
Definition extconf.c:950
char * exec_file
if it's an exec, you'll have both the /var/tmp to read, and the original script

References ast_calloc, ast_include_find(), ast_include_find(), ast_includes_destroy(), AST_LIST_INSERT_TAIL, ast_log, ast_strdup, ast_strlen_zero(), ast_strlen_zero(), CONFIG_STATEMENT_EXEC, CONFIG_STATEMENT_INCLUDE, CONFIG_STATEMENT_TRYINCLUDE, ast_config_include::exec, ast_config_include::exec_file, F_OK, ast_config_include::include_location_file, ast_config_include::include_location_lineno, ast_config_include::include_type, ast_config_include::included_file, ast_config_include::included_files, ast_config_include::inclusion_count, LOG_WARNING, make_fn(), MY_GLOB_FLAGS, ast_config_include::next, NULL, config_included_file::path, and PATH_MAX.

Referenced by AST_TEST_DEFINE(), and process_text_line().

◆ ast_include_rename()

void ast_include_rename ( struct ast_config conf,
const char *  from_file,
const char *  to_file 
)

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

471{
472 struct ast_config_include *incl;
473 struct ast_category *cat;
474 char *str;
475
476 int from_len = strlen(from_file);
477 int to_len = strlen(to_file);
478
479 if (strcmp(from_file, to_file) == 0) /* no use wasting time if the name is the same */
480 return;
481
482 /* the manager code allows you to read in one config file, then
483 * write it back out under a different name. But, the new arrangement
484 * ties output lines to the file name. So, before you try to write
485 * the config file to disk, better riffle thru the data and make sure
486 * the file names are changed.
487 */
488 /* file names are on categories, includes (of course), and on variables. So,
489 * traverse all this and swap names */
490
491 for (incl = conf->includes_root; incl; incl = incl->next) {
492 if (strcmp(incl->include_location_file, from_file) == 0) {
493 if (from_len >= to_len)
494 strcpy(incl->include_location_file, to_file);
495 else {
496 /* Keep the old filename if the allocation fails. */
497 str = ast_strdup(to_file);
498 if (str) {
501 }
502 }
503 }
504 }
505 for (cat = conf->root; cat; cat = cat->next) {
506 struct ast_variable **prev;
507 struct ast_variable *v;
508 struct ast_variable *new_var;
509
510 if (strcmp(cat->file, from_file) == 0) {
511 if (from_len >= to_len)
512 strcpy(cat->file, to_file);
513 else {
514 /* Keep the old filename if the allocation fails. */
515 str = ast_strdup(to_file);
516 if (str) {
517 ast_free(cat->file);
518 cat->file = str;
519 }
520 }
521 }
522 for (prev = &cat->root, v = cat->root; v; prev = &v->next, v = v->next) {
523 if (strcmp(v->file, from_file)) {
524 continue;
525 }
526
527 /*
528 * Calculate actual space available. The file string is
529 * intentionally stuffed before the name string just so we can
530 * do this.
531 */
532 if (to_len < v->name - v->file) {
533 /* The new name will fit in the available space. */
534 str = (char *) v->file;/* Stupid compiler complains about discarding qualifiers even though I used a cast. */
535 strcpy(str, to_file);/* SAFE */
536 continue;
537 }
538
539 /* Keep the old filename if the allocation fails. */
540 new_var = ast_variable_new(v->name, v->value, to_file);
541 if (!new_var) {
542 continue;
543 }
544
545 /* Move items from the old list node to the replacement node. */
546 ast_variable_move(new_var, v);
547
548 /* Replace the old node in the list with the new node. */
549 new_var->next = v->next;
550 if (cat->last == v) {
551 cat->last = new_var;
552 }
553 *prev = new_var;
554
556
557 v = new_var;
558 }
559 }
560}
#define ast_free(a)
Definition astmm.h:180
#define ast_variable_new(name, value, filename)
static void ast_variable_destroy(struct ast_variable *doomed)
static void ast_variable_move(struct ast_variable *dst_var, struct ast_variable *src_var)

References ast_free, ast_strdup, ast_variable_destroy(), ast_variable_move(), ast_variable_new, ast_variable::file, ast_category::file, ast_config_include::include_location_file, ast_category::last, name, ast_variable::name, ast_variable::next, ast_category::next, ast_config_include::next, ast_category::root, str, and ast_variable::value.

Referenced by action_updateconfig().

◆ ast_load_realtime()

struct ast_variable * ast_load_realtime ( const char *  family,
  ... 
)

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

3774{
3775 RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
3776 int field_res = 0;
3777 va_list ap;
3778
3779 va_start(ap, family);
3780 if (realtime_arguments_to_fields(ap, &fields)) {
3781 field_res = -1;
3782 }
3783 va_end(ap);
3784
3785 if (field_res) {
3786 return NULL;
3787 }
3788
3789 if (!fields) {
3790 return NULL;
3791 }
3792
3793 return ast_load_realtime_fields(family, fields);
3794}
struct ast_variable * ast_load_realtime_fields(const char *family, const struct ast_variable *fields)
Retrieve realtime configuration.

References ast_load_realtime_fields(), ast_variables_destroy(), NULL, RAII_VAR, and realtime_arguments_to_fields.

Referenced by conf_run(), copy_plain_file(), find_conf_realtime(), find_load_queue_rt_friendly(), find_realtime(), find_user_realtime(), find_user_realtime(), leave_queue(), load_realtime_musiconhold(), queue_function_queuegetchannel(), queue_function_queuewaitingcount(), realtime_peer(), realtime_switch_common(), realtime_user(), and rt_extend_conf().

◆ ast_load_realtime_all()

struct ast_variable * ast_load_realtime_all ( const char *  family,
  ... 
)

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

3722{
3723 RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
3724 struct ast_variable *res = NULL;
3725 va_list ap;
3726
3727 va_start(ap, family);
3728 realtime_arguments_to_fields(ap, &fields);
3729 va_end(ap);
3730
3731 if (fields) {
3732 res = ast_load_realtime_all_fields(family, fields);
3733 }
3734
3735 return res;
3736}
struct ast_variable * ast_load_realtime_all_fields(const char *family, const struct ast_variable *fields)

References ast_load_realtime_all_fields(), ast_variables_destroy(), NULL, RAII_VAR, and realtime_arguments_to_fields.

Referenced by cli_realtime_load(), function_realtime_read(), function_realtime_readdestroy(), and realtimefield_read().

◆ ast_load_realtime_all_fields()

struct ast_variable * ast_load_realtime_all_fields ( const char *  family,
const struct ast_variable fields 
)

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

3689{
3690 struct ast_config_engine *eng;
3691 char db[256];
3692 char table[256];
3693 struct ast_variable *res=NULL;
3694 int i;
3695
3696 for (i = 1; ; i++) {
3697 if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3698 if (eng->realtime_func) {
3699 res = eng->realtime_func(db, table, fields);
3700
3701 /* If a backend returns CONFIG_RT_NOT_FOUND, stop iteration and return NULL,
3702 * indicating that the requested record does not exist and no failover should occur.
3703 * Only continue iteration if the result is NULL and not CONFIG_RT_NOT_FOUND,
3704 * which signals a backend failure.
3705 */
3706 if (res == CONFIG_RT_NOT_FOUND) {
3707 return NULL;
3708 }
3709 if (res) {
3710 return res;
3711 }
3712 }
3713 } else {
3714 return NULL;
3715 }
3716 }
3717
3718 return res;
3719}
#define CONFIG_RT_NOT_FOUND
realtime_var_get * realtime_func

References CONFIG_RT_NOT_FOUND, db, find_engine(), NULL, and ast_config_engine::realtime_func.

Referenced by ast_load_realtime_all(), and ast_load_realtime_fields().

◆ ast_load_realtime_fields()

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 3738 of file main/config.c.

3739{
3740 struct ast_variable *res;
3741 struct ast_variable *cur;
3742 struct ast_variable **prev;
3743
3744 res = ast_load_realtime_all_fields(family, fields);
3745
3746 /* Filter the list. */
3747 prev = &res;
3748 cur = res;
3749 while (cur) {
3750 if (ast_strlen_zero(cur->value)) {
3751 /* Eliminate empty entries */
3752 struct ast_variable *next;
3753
3754 next = cur->next;
3755 *prev = next;
3757 cur = next;
3758 } else {
3759 /* Make blank entries empty and keep them. */
3760 if (cur->value[0] == ' ' && cur->value[1] == '\0') {
3761 char *vptr = (char *) cur->value;
3762
3763 vptr[0] = '\0';
3764 }
3765
3766 prev = &cur->next;
3767 cur = cur->next;
3768 }
3769 }
3770 return res;
3771}
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65

References ast_load_realtime_all_fields(), ast_strlen_zero(), ast_variable_destroy(), ast_variable::next, ast_category::next, ast_category::prev, and ast_variable::value.

Referenced by ast_load_realtime(), and sorcery_realtime_retrieve_fields().

◆ ast_load_realtime_multientry()

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 3889 of file main/config.c.

3890{
3891 RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
3892 va_list ap;
3893
3894 va_start(ap, family);
3895 realtime_arguments_to_fields(ap, &fields);
3896 va_end(ap);
3897
3898 if (!fields) {
3899 return NULL;
3900 }
3901
3902 return ast_load_realtime_multientry_fields(family, fields);
3903}
struct ast_config * ast_load_realtime_multientry_fields(const char *family, const struct ast_variable *fields)
Retrieve realtime configuration.

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

Referenced by __queues_show(), conf_exec(), find_load_queue_rt_friendly(), find_realtime(), load_module(), load_realtime_musiconhold(), load_realtime_queues(), load_realtime_rules(), named_acl_find_realtime(), realtime_directory(), realtime_switch_common(), set_member_value(), show_users_realtime(), and update_realtime_members().

◆ ast_load_realtime_multientry_fields()

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 3863 of file main/config.c.

3864{
3865 struct ast_config_engine *eng;
3866 char db[256];
3867 char table[256];
3868 struct ast_config *res = NULL;
3869 int i;
3870
3871 for (i = 1; ; i++) {
3872 if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3873 if (eng->realtime_multi_func && (res = eng->realtime_multi_func(db, table, fields))) {
3874 /* If we were returned an empty cfg, destroy it and return NULL */
3875 if (!res->root) {
3876 ast_config_destroy(res);
3877 res = NULL;
3878 }
3879 break;
3880 }
3881 } else {
3882 break;
3883 }
3884 }
3885
3886 return res;
3887}
realtime_multi_get * realtime_multi_func

References ast_config_destroy(), db, find_engine(), NULL, ast_config_engine::realtime_multi_func, and ast_config::root.

Referenced by ast_load_realtime_multientry(), and sorcery_realtime_retrieve_multiple().

◆ ast_parse_arg()

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 4094 of file main/config.c.

4096{
4097 va_list ap;
4098 int error = 0;
4099
4100 va_start(ap, p_result);
4101 switch (flags & PARSE_TYPE) {
4102 case PARSE_INT32:
4103 {
4104 long int x = 0;
4105 int32_t *result = p_result;
4106 int32_t def = result ? *result : 0, high = INT32_MAX, low = INT32_MIN;
4107 char *endptr = NULL;
4108
4109 /* optional arguments: default value and/or (low, high) */
4110 if (flags & PARSE_DEFAULT) {
4111 def = va_arg(ap, int32_t);
4112 }
4113 if (flags & (PARSE_IN_RANGE | PARSE_OUT_RANGE)) {
4114 low = va_arg(ap, int32_t);
4115 high = va_arg(ap, int32_t);
4116 }
4117 if (ast_strlen_zero(arg)) {
4118 error = 1;
4119 goto int32_done;
4120 }
4121 errno = 0;
4122 x = strtol(arg, &endptr, 0);
4123 if (*endptr || errno || x < INT32_MIN || x > INT32_MAX) {
4124 /* Parse error, or type out of int32_t bounds */
4125 error = 1;
4126 goto int32_done;
4127 }
4128 error = (x < low) || (x > high);
4129 if (flags & PARSE_RANGE_DEFAULTS) {
4130 if (x < low) {
4131 def = low;
4132 } else if (x > high) {
4133 def = high;
4134 }
4135 }
4136 if (flags & PARSE_OUT_RANGE) {
4137 error = !error;
4138 }
4139int32_done:
4140 if (result) {
4141 *result = error ? def : x;
4142 }
4143
4144 ast_debug(3, "extract int from [%s] in [%d, %d] gives [%ld](%d)\n",
4145 arg, low, high, result ? *result : x, error);
4146 break;
4147 }
4148
4149 case PARSE_UINT32:
4150 {
4151 unsigned long int x = 0;
4152 uint32_t *result = p_result;
4153 uint32_t def = result ? *result : 0, low = 0, high = UINT32_MAX;
4154 char *endptr = NULL;
4155
4156 /* optional argument: first default value, then range */
4157 if (flags & PARSE_DEFAULT) {
4158 def = va_arg(ap, uint32_t);
4159 }
4160 if (flags & (PARSE_IN_RANGE|PARSE_OUT_RANGE)) {
4161 /* range requested, update bounds */
4162 low = va_arg(ap, uint32_t);
4163 high = va_arg(ap, uint32_t);
4164 }
4165
4166 if (ast_strlen_zero(arg)) {
4167 error = 1;
4168 goto uint32_done;
4169 }
4170 /* strtoul will happily and silently negate negative numbers */
4171 arg = ast_skip_blanks(arg);
4172 if (*arg == '-') {
4173 error = 1;
4174 goto uint32_done;
4175 }
4176 errno = 0;
4177 x = strtoul(arg, &endptr, 0);
4178 if (*endptr || errno || x > UINT32_MAX) {
4179 error = 1;
4180 goto uint32_done;
4181 }
4182 error = (x < low) || (x > high);
4183 if (flags & PARSE_RANGE_DEFAULTS) {
4184 if (x < low) {
4185 def = low;
4186 } else if (x > high) {
4187 def = high;
4188 }
4189 }
4190 if (flags & PARSE_OUT_RANGE) {
4191 error = !error;
4192 }
4193uint32_done:
4194 if (result) {
4195 *result = error ? def : x;
4196 }
4197 ast_debug(3, "extract uint from [%s] in [%u, %u] gives [%lu](%d)\n",
4198 arg, low, high, result ? *result : x, error);
4199 break;
4200 }
4201
4202 case PARSE_TIMELEN:
4203 {
4204 int x = 0;
4205 int *result = p_result;
4206 int def = result ? *result : 0;
4207 int high = INT_MAX;
4208 int low = INT_MIN;
4209 enum ast_timelen defunit;
4210
4211 defunit = va_arg(ap, enum ast_timelen);
4212 /* optional arguments: default value and/or (low, high) */
4213 if (flags & PARSE_DEFAULT) {
4214 def = va_arg(ap, int);
4215 }
4216 if (flags & (PARSE_IN_RANGE | PARSE_OUT_RANGE)) {
4217 low = va_arg(ap, int);
4218 high = va_arg(ap, int);
4219 }
4220 if (ast_strlen_zero(arg)) {
4221 error = 1;
4222 goto timelen_done;
4223 }
4224 error = ast_app_parse_timelen(arg, &x, defunit);
4225 if (error || x < INT_MIN || x > INT_MAX) {
4226 /* Parse error, or type out of int bounds */
4227 error = 1;
4228 goto timelen_done;
4229 }
4230 error = (x < low) || (x > high);
4231 if (flags & PARSE_RANGE_DEFAULTS) {
4232 if (x < low) {
4233 def = low;
4234 } else if (x > high) {
4235 def = high;
4236 }
4237 }
4238 if (flags & PARSE_OUT_RANGE) {
4239 error = !error;
4240 }
4241timelen_done:
4242 if (result) {
4243 *result = error ? def : x;
4244 }
4245
4246 ast_debug(3, "extract timelen from [%s] in [%d, %d] gives [%d](%d)\n",
4247 arg, low, high, result ? *result : x, error);
4248 break;
4249 }
4250
4251 case PARSE_DOUBLE:
4252 {
4253 double *result = p_result;
4254 double x = 0, def = result ? *result : 0, low = -HUGE_VAL, high = HUGE_VAL;
4255 char *endptr = NULL;
4256
4257 /* optional argument: first default value, then range */
4258 if (flags & PARSE_DEFAULT) {
4259 def = va_arg(ap, double);
4260 }
4261 if (flags & (PARSE_IN_RANGE | PARSE_OUT_RANGE)) {
4262 /* range requested, update bounds */
4263 low = va_arg(ap, double);
4264 high = va_arg(ap, double);
4265 }
4266 if (ast_strlen_zero(arg)) {
4267 error = 1;
4268 goto double_done;
4269 }
4270 errno = 0;
4271 x = strtod(arg, &endptr);
4272 if (*endptr || errno == ERANGE) {
4273 error = 1;
4274 goto double_done;
4275 }
4276 error = (x < low) || (x > high);
4277 if (flags & PARSE_OUT_RANGE) {
4278 error = !error;
4279 }
4280double_done:
4281 if (result) {
4282 *result = error ? def : x;
4283 }
4284 ast_debug(3, "extract double from [%s] in [%f, %f] gives [%f](%d)\n",
4285 arg, low, high, result ? *result : x, error);
4286 break;
4287 }
4288 case PARSE_ADDR:
4289 {
4290 struct ast_sockaddr *addr = (struct ast_sockaddr *)p_result;
4291
4292 if (!ast_sockaddr_parse(addr, arg, flags & PARSE_PORT_MASK)) {
4293 error = 1;
4294 }
4295
4296 ast_debug(3, "extract addr from %s gives %s(%d)\n",
4297 arg, ast_sockaddr_stringify(addr), error);
4298
4299 break;
4300 }
4301 case PARSE_INADDR: /* TODO Remove this (use PARSE_ADDR instead). */
4302 {
4303 char *port, *buf;
4304 struct sockaddr_in _sa_buf; /* buffer for the result */
4305 struct sockaddr_in *sa = p_result ?
4306 (struct sockaddr_in *)p_result : &_sa_buf;
4307 /* default is either the supplied value or the result itself */
4308 struct sockaddr_in *def = (flags & PARSE_DEFAULT) ?
4309 va_arg(ap, struct sockaddr_in *) : sa;
4310 struct ast_sockaddr addr = { {0,} };
4311
4312 memset(&_sa_buf, '\0', sizeof(_sa_buf)); /* clear buffer */
4313 /* duplicate the string to strip away the :port */
4314 port = ast_strdupa(arg);
4315 buf = strsep(&port, ":");
4316 sa->sin_family = AF_INET; /* assign family */
4317 /*
4318 * honor the ports flag setting, assign default value
4319 * in case of errors or field unset.
4320 */
4321 flags &= PARSE_PORT_MASK; /* the only flags left to process */
4322 if (port) {
4323 if (flags == PARSE_PORT_FORBID) {
4324 error = 1; /* port was forbidden */
4325 sa->sin_port = def->sin_port;
4326 } else if (flags == PARSE_PORT_IGNORE)
4327 sa->sin_port = def->sin_port;
4328 else /* accept or require */
4329 sa->sin_port = htons(strtol(port, NULL, 0));
4330 } else {
4331 sa->sin_port = def->sin_port;
4332 if (flags == PARSE_PORT_REQUIRE)
4333 error = 1;
4334 }
4335 /* Now deal with host part, even if we have errors before. */
4336 if (ast_sockaddr_resolve_first_af(&addr, buf, PARSE_PORT_FORBID, AF_INET)) {
4337 error = 1;
4338 sa->sin_addr = def->sin_addr;
4339 } else {
4340 struct sockaddr_in tmp;
4341 ast_sockaddr_to_sin(&addr, &tmp);
4342 sa->sin_addr = tmp.sin_addr;
4343 }
4344 ast_debug(3,
4345 "extract inaddr from [%s] gives [%s:%d](%d)\n",
4346 arg, ast_inet_ntoa(sa->sin_addr),
4347 ntohs(sa->sin_port), error);
4348 break;
4349 }
4350 }
4351 va_end(ap);
4352 return error;
4353}
#define INT32_MAX
Definition ast_expr2f.c:79
#define INT32_MIN
Definition ast_expr2f.c:70
#define UINT32_MAX
Definition ast_expr2f.c:88
char * strsep(char **str, const char *delims)
char buf[BUFSIZE]
Definition eagi_proxy.c:66
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
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
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition netsock2.h:256
#define ast_sockaddr_to_sin(addr, sin)
Converts a struct ast_sockaddr to a struct sockaddr_in.
Definition netsock2.h:765
int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
Parse an IPv4 or IPv6 address string.
Definition netsock2.c:230
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
Definition utils.c:964
char *attribute_pure ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
Definition strings.h:161
Socket address structure.
Definition netsock2.h:97
int error(const char *format,...)

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, ast_strdupa, ast_strlen_zero(), buf, errno, error(), INT32_MAX, INT32_MIN, NULL, PARSE_ADDR, PARSE_DEFAULT, PARSE_DOUBLE, PARSE_IN_RANGE, PARSE_INADDR, PARSE_INT32, PARSE_OUT_RANGE, PARSE_PORT_FORBID, PARSE_PORT_IGNORE, PARSE_PORT_MASK, PARSE_PORT_REQUIRE, PARSE_RANGE_DEFAULTS, PARSE_TIMELEN, PARSE_TYPE, PARSE_UINT32, result, strsep(), and UINT32_MAX.

Referenced by __ast_http_load(), __init_manager(), app_exec(), AST_TEST_DEFINE(), ast_tls_read_conf(), build_peer(), build_peer(), build_user(), configure_local_rtp(), double_handler_fn(), general_set(), iax2_call(), iax2_request(), int_handler_fn(), load_asterisk_conf(), load_config(), load_config(), new_realtime_sqlite3_db(), realtime_peer(), reload_config(), rtp_reload(), sample_rate_handler(), set_config(), setup_rtp_connection(), setup_rtp_remote(), setup_udptl_connection(), sockaddr_handler_fn(), timelen_handler_fn(), uint_handler_fn(), and xfer_set().

◆ ast_realtime_decode_chunk()

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 4062 of file main/config.c.

4063{
4064 char *orig = chunk;
4065 for (; *chunk; chunk++) {
4066 if (*chunk == '^' && strchr("0123456789ABCDEFabcdef", chunk[1]) && strchr("0123456789ABCDEFabcdef", chunk[2])) {
4067 sscanf(chunk + 1, "%02hhX", (unsigned char *)chunk);
4068 memmove(chunk + 1, chunk + 3, strlen(chunk + 3) + 1);
4069 }
4070 }
4071 return orig;
4072}

Referenced by realtime_multi_pgsql(), and realtime_pgsql().

◆ ast_realtime_enabled()

int ast_realtime_enabled ( void  )

Check if there's any realtime engines loaded.

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

3812{
3813 return config_maps ? 1 : 0;
3814}
static struct ast_config_map * config_maps

References config_maps.

Referenced by action_coresettings(), ast_check_realtime(), and handle_show_settings().

◆ ast_realtime_encode_chunk()

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 4074 of file main/config.c.

4075{
4076 if (!strchr(chunk, ';') && !strchr(chunk, '^')) {
4077 ast_str_set(dest, maxlen, "%s", chunk);
4078 } else {
4079 ast_str_reset(*dest);
4080 for (; *chunk; chunk++) {
4081 if (strchr(";^", *chunk)) {
4082 ast_str_append(dest, maxlen, "^%02hhX", *chunk);
4083 } else {
4084 ast_str_append(dest, maxlen, "%c", *chunk);
4085 }
4086 }
4087 }
4088 return ast_str_buffer(*dest);
4089}
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_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition strings.h:1113
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition strings.h:761

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

◆ ast_realtime_is_mapping_defined()

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 3448 of file main/config.c.

3449{
3450 struct ast_config_map *map;
3452
3453 for (map = config_maps; map; map = map->next) {
3454 if (!strcasecmp(family, map->name)) {
3455 return 1;
3456 }
3457 }
3458 ast_debug(5, "Failed to find a realtime mapping for %s\n", family);
3459
3460 return 0;
3461}
struct ast_config_map * next
const char * name

References ast_debug, config_lock, config_maps, lock, ast_config_map::name, ast_config_map::next, and SCOPED_MUTEX.

Referenced by ast_named_acl_find(), and sorcery_realtime_open().

◆ ast_realtime_require_field()

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 3816 of file main/config.c.

3817{
3818 struct ast_config_engine *eng;
3819 char db[256];
3820 char table[256];
3821 va_list ap, aq;
3822 int res = -1, i;
3823
3824 va_start(ap, family);
3825 for (i = 1; ; i++) {
3826 if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3827 va_copy(aq, ap);
3828 /* If the require succeeds, it returns 0. */
3829 if (eng->require_func && !(res = eng->require_func(db, table, aq))) {
3830 va_end(aq);
3831 break;
3832 }
3833 va_end(aq);
3834 } else {
3835 break;
3836 }
3837 }
3838 va_end(ap);
3839
3840 return res;
3841}
realtime_require * require_func

References db, find_engine(), and ast_config_engine::require_func.

Referenced by ast_queue_log(), change_password_realtime(), conf_run(), load_module(), load_module(), load_module(), load_module(), and logger_queue_rt_start().

◆ ast_rq_is_int()

int ast_rq_is_int ( require_type  type)
inline

Check if require type is an integer type.

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

Referenced by require_mysql(), require_odbc(), and require_pgsql().

◆ ast_store_realtime()

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 4007 of file main/config.c.

4008{
4009 RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
4010 va_list ap;
4011
4012 va_start(ap, family);
4013 realtime_arguments_to_fields(ap, &fields);
4014 va_end(ap);
4015
4016 if (!fields) {
4017 return -1;
4018 }
4019
4020 return ast_store_realtime_fields(family, fields);
4021}
int ast_store_realtime_fields(const char *family, const struct ast_variable *fields)
Create realtime configuration.

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

Referenced by ast_queue_log(), cli_realtime_store(), copy_plain_file(), function_realtime_store(), leave_voicemail(), and msg_create_from_file().

◆ ast_store_realtime_fields()

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 3986 of file main/config.c.

3987{
3988 struct ast_config_engine *eng;
3989 int res = -1, i;
3990 char db[256];
3991 char table[256];
3992
3993 for (i = 1; ; i++) {
3994 if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3995 /* If the store succeeds, it returns >= 0*/
3996 if (eng->store_func && ((res = eng->store_func(db, table, fields)) >= 0)) {
3997 break;
3998 }
3999 } else {
4000 break;
4001 }
4002 }
4003
4004 return res;
4005}

References db, find_engine(), and ast_config_engine::store_func.

Referenced by ast_store_realtime(), sorcery_realtime_create(), and sorcery_realtime_update().

◆ ast_unload_realtime()

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 3843 of file main/config.c.

3844{
3845 struct ast_config_engine *eng;
3846 char db[256];
3847 char table[256];
3848 int res = -1, i;
3849
3850 for (i = 1; ; i++) {
3851 if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3852 if (eng->unload_func) {
3853 /* Do this for ALL engines */
3854 res = eng->unload_func(db, table);
3855 }
3856 } else {
3857 break;
3858 }
3859 }
3860 return res;
3861}
realtime_unload * unload_func

References db, find_engine(), and ast_config_engine::unload_func.

Referenced by __unload_module(), load_config_force(), logger_queue_init(), reload(), reload(), reload_config(), reload_logger(), unload_module(), unload_module(), and unload_module().

◆ ast_update2_realtime()

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 3962 of file main/config.c.

3963{
3964 RAII_VAR(struct ast_variable *, lookup_fields, NULL, ast_variables_destroy);
3965 RAII_VAR(struct ast_variable *, update_fields, NULL, ast_variables_destroy);
3966 va_list ap;
3967
3968 va_start(ap, family);
3969 /* XXX: If we wanted to pass no lookup fields (select all), we'd be
3970 * out of luck. realtime_arguments_to_fields expects at least one key
3971 * value pair. */
3972 realtime_arguments_to_fields(ap, &lookup_fields);
3973 va_end(ap);
3974
3975 va_start(ap, family);
3976 realtime_arguments_to_fields2(ap, 1, &update_fields);
3977 va_end(ap);
3978
3979 if (!lookup_fields || !update_fields) {
3980 return -1;
3981 }
3982
3983 return ast_update2_realtime_fields(family, lookup_fields, update_fields);
3984}
static int realtime_arguments_to_fields2(va_list ap, int skip, struct ast_variable **result)
int ast_update2_realtime_fields(const char *family, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields)
Update realtime configuration.

References ast_update2_realtime_fields(), ast_variables_destroy(), NULL, RAII_VAR, realtime_arguments_to_fields, and realtime_arguments_to_fields2().

Referenced by change_password_realtime(), and cli_realtime_update2().

◆ ast_update2_realtime_fields()

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 3942 of file main/config.c.

3943{
3944 struct ast_config_engine *eng;
3945 int res = -1, i;
3946 char db[256];
3947 char table[256];
3948
3949 for (i = 1; ; i++) {
3950 if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3951 if (eng->update2_func && !(res = eng->update2_func(db, table, lookup_fields, update_fields))) {
3952 break;
3953 }
3954 } else {
3955 break;
3956 }
3957 }
3958
3959 return res;
3960}
realtime_update2 * update2_func

References db, find_engine(), and ast_config_engine::update2_func.

Referenced by ast_update2_realtime().

◆ ast_update_realtime()

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 3926 of file main/config.c.

3927{
3928 RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
3929 va_list ap;
3930
3931 va_start(ap, lookup);
3932 realtime_arguments_to_fields(ap, &fields);
3933 va_end(ap);
3934
3935 if (!fields) {
3936 return -1;
3937 }
3938
3939 return ast_update_realtime_fields(family, keyfield, lookup, fields);
3940}
int ast_update_realtime_fields(const char *family, const char *keyfield, const char *lookup, const struct ast_variable *fields)
Update realtime configuration.

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

Referenced by cli_realtime_update(), conf_run(), function_realtime_write(), leave_voicemail(), realtime_update_peer(), rename_file(), rt_extend_conf(), set_queue_member_pause(), and update_realtime_member_field().

◆ ast_update_realtime_fields()

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 3905 of file main/config.c.

3906{
3907 struct ast_config_engine *eng;
3908 int res = -1, i;
3909 char db[256];
3910 char table[256];
3911
3912 for (i = 1; ; i++) {
3913 if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3914 /* If the update succeeds, it returns >= 0. */
3915 if (eng->update_func && ((res = eng->update_func(db, table, keyfield, lookup, fields)) >= 0)) {
3916 break;
3917 }
3918 } else {
3919 break;
3920 }
3921 }
3922
3923 return res;
3924}
realtime_update * update_func

References db, find_engine(), and ast_config_engine::update_func.

Referenced by ast_update_realtime(), and sorcery_realtime_update().

◆ ast_variable_append()

static void ast_variable_append ( struct ast_category category,
struct ast_variable variable 
)

◆ ast_variable_browse()

static struct ast_variable * ast_variable_browse ( const struct ast_config config,
const char *  category_name 
)

Definition at line 1213 of file extconf.c.

1214{
1215 struct ast_category *cat = NULL;
1216
1217 if (category && config->last_browse && (config->last_browse->name == category))
1218 cat = config->last_browse;
1219 else
1220 cat = ast_category_get(config, category);
1221
1222 return (cat) ? cat->root : NULL;
1223}
static struct ast_category * ast_category_get(const struct ast_config *config, const char *category_name)
Definition extconf.c:1208

References ast_category_get(), ast_category_get(), config, NULL, and ast_category::root.

Referenced by __ast_http_load(), __ast_http_post_load(), __ast_sorcery_apply_config(), __init_manager(), _dsp_init(), aco_process_category_options(), adsi_load(), ast_cli_perms_init(), AST_TEST_DEFINE(), ast_variable_retrieve(), build_calendar(), build_device(), caldav_load_calendar(), conf_exec(), config_module(), do_reload(), do_say(), ewscal_load_calendar(), exchangecal_load_calendar(), find_conf(), get_defaults(), handle_cli_dialplan_save(), iax_template_parse(), ical_load_calendar(), init_logger_chain(), load_aliases(), load_asterisk_conf(), load_common(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_general_config(), load_module(), load_moh_classes(), load_odbc_config(), load_users(), load_zonemessages(), loader_config_init(), mbl_load_adapter(), mbl_load_config(), mbl_load_device(), new_realtime_sqlite3_db(), odbc_load_module(), parse_config(), parse_config(), parse_general_options(), parse_tone_zone(), pbx_load_config(), process_my_load_module(), read_pjproject_startup_options(), realtime_directory(), reload(), reload_config(), reload_config(), reload_followme(), reload_module(), reload_module(), reload_module(), reload_queue_rules(), reload_single_queue(), rtp_reload(), run_startup_commands(), search_directory_sub(), set_config(), set_config(), set_config(), setup_dahdi_int(), show_users_realtime(), sla_build_station(), sla_build_trunk(), smdi_load(), tds_load_module(), tds_load_module(), test_config_validity(), and xmldoc_load_documentation().

◆ ast_variable_browse_filtered()

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

◆ ast_variable_delete()

int ast_variable_delete ( struct ast_category category,
const char *  variable,
const char *  match,
const char *  line 
)

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

1602{
1603 struct ast_variable *cur, *prev=NULL, *curn;
1604 int res = -1;
1605 int num_item = 0;
1606 int req_item;
1607
1608 req_item = -1;
1609 if (!ast_strlen_zero(line)) {
1610 /* Requesting to delete by item number. */
1611 if (sscanf(line, "%30d", &req_item) != 1
1612 || req_item < 0) {
1613 /* Invalid item number to delete. */
1614 return -1;
1615 }
1616 }
1617
1618 prev = NULL;
1619 cur = category->root;
1620 while (cur) {
1621 curn = cur->next;
1622 /* Delete by item number or by variable name with optional value. */
1623 if ((0 <= req_item && num_item == req_item)
1624 || (req_item < 0 && !strcasecmp(cur->name, variable)
1625 && (ast_strlen_zero(match) || !strcasecmp(cur->value, match)))) {
1626 if (prev) {
1627 prev->next = cur->next;
1628 if (cur == category->last)
1629 category->last = prev;
1630 } else {
1631 category->root = cur->next;
1632 if (cur == category->last)
1633 category->last = NULL;
1634 }
1636 res = 0;
1637 } else
1638 prev = cur;
1639
1640 cur = curn;
1641 ++num_item;
1642 }
1643 return res;
1644}

References ast_strlen_zero(), ast_variable_destroy(), ast_category::last, match(), ast_variable::name, ast_variable::next, ast_category::next, NULL, ast_category::prev, ast_category::root, and ast_variable::value.

Referenced by handle_updates().

◆ ast_variable_find()

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 919 of file main/config.c.

920{
921 return ast_variable_find_in_list(category->root, variable);
922}
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.

References ast_variable_find_in_list(), and ast_category::root.

Referenced by AST_TEST_DEFINE(), AST_TEST_DEFINE(), ast_variable_retrieve_filtered(), and extension_length_comparator().

◆ ast_variable_find_in_list()

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 1014 of file main/config.c.

1015{
1016 const struct ast_variable *v;
1017
1018 for (v = list; v; v = v->next) {
1019 if (!strcasecmp(variable, v->name)) {
1020 return v->value;
1021 }
1022 }
1023 return NULL;
1024}

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

Referenced by ast_ari_callback(), ast_geoloc_eprofile_to_uri(), ast_geoloc_gml_validate_varlist(), ast_sorcery_changeset_create(), AST_TEST_DEFINE(), ast_variable_find(), geoloc_civicaddr_list_to_xml(), geoloc_eprofile_to_intermediate(), geoloc_gml_list_to_xml(), handle_export_primitives(), incoming_ws_established_cb(), load_realtime_musiconhold(), retrieve_cert_from_url(), validate_location_info(), and websocket_attempted_cb().

◆ ast_variable_find_last_in_list()

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 1026 of file main/config.c.

1027{
1028 const struct ast_variable *v;
1029 const char *found = NULL;
1030
1031 for (v = list; v; v = v->next) {
1032 if (!strcasecmp(variable, v->name)) {
1033 found = v->value;
1034 }
1035 }
1036 return found;
1037}

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

Referenced by AST_TEST_DEFINE(), handle_aor(), handle_auth(), handle_endpoint(), handle_identify(), handle_phoneprov(), handle_registrations(), is_variable_true(), and wizard_apply_handler().

◆ ast_variable_find_variable_in_list()

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 924 of file main/config.c.

925{
926 const struct ast_variable *v;
927
928 for (v = list; v; v = v->next) {
929 if (!strcasecmp(variable_name, v->name)) {
930 return v;
931 }
932 }
933 return NULL;
934}

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

Referenced by ast_variable_lists_match(), and realtime_sorcery_store().

◆ ast_variable_insert()

void ast_variable_insert ( struct ast_category category,
struct ast_variable variable,
const char *  line 
)

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

587{
588 struct ast_variable *cur = category->root;
589 int lineno;
590 int insertline;
591
592 if (!variable || sscanf(line, "%30d", &insertline) != 1) {
593 return;
594 }
595 if (!insertline) {
596 variable->next = category->root;
597 category->root = variable;
598 } else {
599 for (lineno = 1; lineno < insertline; lineno++) {
600 cur = cur->next;
601 if (!cur->next) {
602 break;
603 }
604 }
605 variable->next = cur->next;
606 cur->next = variable;
607 }
608}

References ast_variable::lineno, ast_variable::next, and ast_category::root.

Referenced by AST_TEST_DEFINE(), AST_TEST_DEFINE(), and handle_updates().

◆ ast_variable_list_append_hint()

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 733 of file main/config.c.

734{
735 struct ast_variable *curr;
736 struct ast_variable *sh = search_hint;
737 ast_assert(head != NULL);
738
739 if (!*head) {
740 *head = newvar;
741 } else {
742 if (sh == NULL) {
743 sh = *head;
744 }
745 for (curr = sh; curr->next; curr = curr->next);
746 curr->next = newvar;
747 }
748
749 for (curr = newvar; curr->next; curr = curr->next);
750
751 return curr;
752}
#define ast_assert(a)
Definition utils.h:776

References ast_assert, ast_variable::next, and NULL.

Referenced by ast_json_nvp_array_to_ast_variables(), ast_json_to_ast_variables(), ast_sorcery_objectset_create2(), and AST_TEST_DEFINE().

◆ ast_variable_list_from_quoted_string()

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 813 of file main/config.c.

815{
816 char item_sep;
817 char nv_sep;
818 char quote;
819 struct ast_variable *new_list = NULL;
820 struct ast_variable *new_var = NULL;
821 char *item_string;
822 char *item;
823 char *item_name;
824 char *item_value;
825
826 if (ast_strlen_zero(input)) {
827 return NULL;
828 }
829
830 item_sep = ast_strlen_zero(item_separator) ? ',' : item_separator[0];
831 nv_sep = ast_strlen_zero(name_value_separator) ? '=' : name_value_separator[0];
832 quote = ast_strlen_zero(quote_str) ? '"' : quote_str[0];
833 item_string = ast_strip(ast_strdupa(input));
834
835 while ((item = ast_strsep_quoted(&item_string, item_sep, quote, AST_STRSEP_ALL))) {
836 item_name = ast_strsep_quoted(&item, nv_sep, quote, AST_STRSEP_ALL);
837 if (!item_name) {
838 ast_variables_destroy(new_list);
839 return NULL;
840 }
841
842 item_value = ast_strsep_quoted(&item, nv_sep, quote, AST_STRSEP_ALL);
843
844 new_var = ast_variable_new(item_name, item_value ?: "", "");
845 if (!new_var) {
846 ast_variables_destroy(new_list);
847 return NULL;
848 }
849 ast_variable_list_append(&new_list, new_var);
850 }
851 return new_list;
852}
static int quote(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
#define ast_variable_list_append(head, new_var)
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:1935
@ AST_STRSEP_ALL
Definition strings.h:258
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition strings.h:223
static struct aco_type item

References ast_strdupa, ast_strip(), ast_strlen_zero(), AST_STRSEP_ALL, ast_strsep_quoted(), ast_variable_list_append, ast_variable_new, ast_variables_destroy(), item, NULL, and quote().

Referenced by AST_TEST_DEFINE(), and ast_variable_list_from_string().

◆ ast_variable_list_from_string()

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 854 of file main/config.c.

856{
857 return ast_variable_list_from_quoted_string(input, item_separator, name_value_separator, NULL);
858}
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.

References ast_variable_list_from_quoted_string(), and NULL.

◆ ast_variable_list_join()

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 787 of file main/config.c.

789{
790 struct ast_variable *var = (struct ast_variable *)head;
791 struct ast_str *local_str = NULL;
792
793 if (str == NULL || *str == NULL) {
795 if (!local_str) {
796 return NULL;
797 }
798 } else {
799 local_str = *str;
800 }
801
802 for (; var; var = var->next) {
803 ast_str_append(&local_str, 0, "%s%s%s%s%s%s", var->name, name_value_separator, S_OR(quote_char, ""),
804 var->value, S_OR(quote_char, ""), var->next ? item_separator : "");
805 }
806
807 if (str != NULL) {
808 *str = local_str;
809 }
810 return local_str;
811}
#define AST_MAX_USER_FIELD
Definition channel.h:176
#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

References AST_MAX_USER_FIELD, ast_str_append(), ast_str_create, NULL, S_OR, str, and var.

Referenced by add_eprofile_to_channel(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), geoloc_config_list_locations(), geoloc_config_show_profiles(), validate_location_info(), var_list_from_confidence(), var_list_from_loc_info(), and var_list_from_node().

◆ ast_variable_list_replace()

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 754 of file main/config.c.

755{
756 struct ast_variable *v, **prev = head;
757
758 for (v = *head; v; prev = &v->next, v = v->next) {
759 if (!strcmp(v->name, replacement->name)) {
760 replacement->next = v->next;
761 *prev = replacement;
762 ast_free(v);
763 return 0;
764 }
765 }
766
767 return -1;
768}

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

Referenced by ast_geoloc_eprofile_refresh_location(), build_user(), check_access(), mkintf(), process_dahdi(), and set_var_handler().

◆ ast_variable_list_replace_variable()

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 770 of file main/config.c.

772{
773 struct ast_variable *v, **prev = head;
774
775 for (v = *head; v; prev = &v->next, v = v->next) {
776 if (v == old) {
777 new->next = v->next;
778 *prev = new;
779 ast_free(v);
780 return 0;
781 }
782 }
783
784 return -1;
785}

References ast_free, and ast_variable::next.

Referenced by AST_TEST_DEFINE().

◆ ast_variable_list_sort()

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 707 of file main/config.c.

708{
709 struct ast_variable *p, *q;
710 struct ast_variable top;
711 int changed = 1;
712 memset(&top, 0, sizeof(top));
713 top.next = start;
714 if (start != NULL && start->next != NULL) {
715 while (changed) {
716 changed = 0;
717 q = &top;
718 p = top.next;
719 while (p->next != NULL) {
720 if (p->next != NULL && strcmp(p->name, p->next->name) > 0) {
721 q->next = variable_list_switch(p, p->next);
722 changed = 1;
723 }
724 q = p;
725 if (p->next != NULL)
726 p = p->next;
727 }
728 }
729 }
730 return top.next;
731}
static struct ast_variable * variable_list_switch(struct ast_variable *l1, struct ast_variable *l2)

References ast_variable::name, ast_variable::next, NULL, and variable_list_switch().

Referenced by aeap_cli_show(), ast_sip_cli_print_sorcery_objectset(), and config_object_cli_show().

◆ ast_variable_lists_match()

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 956 of file main/config.c.

957{
958 const struct ast_variable *field;
959 int right_count = 0;
960 int left_count = 0;
961
962 if (left == right) {
963 return 1;
964 }
965
966 if (!(left && right)) {
967 return 0;
968 }
969
970 for (field = right; field; field = field->next) {
971 char *space = strrchr(field->name, ' ');
972 const struct ast_variable *old;
973 char * name = (char *)field->name;
974
975 if (space) {
976 name = ast_strdup(field->name);
977 if (!name) {
978 return 0;
979 }
980 name[space - field->name] = '\0';
981 }
982
984 if (name != field->name) {
985 ast_free(name);
986 }
987
988 if (exact_match) {
989 if (!old || strcmp(old->value, field->value)) {
990 return 0;
991 }
992 } else {
993 if (!ast_variables_match(old, field)) {
994 return 0;
995 }
996 }
997
998 right_count++;
999 }
1000
1001 if (exact_match) {
1002 for (field = left; field; field = field->next) {
1003 left_count++;
1004 }
1005
1006 if (right_count != left_count) {
1007 return 0;
1008 }
1009 }
1010
1011 return 1;
1012}
int ast_variables_match(const struct ast_variable *left, const struct ast_variable *right)
Tests 2 variable values to see if they match.
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.

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

Referenced by AST_TEST_DEFINE(), object_type_loaded_observer(), realtime_sorcery(), realtime_sorcery_multi(), sorcery_astdb_retrieve_fields_common(), sorcery_config_fields_cmp(), sorcery_memory_cache_fields_cmp(), and sorcery_memory_fields_cmp().

◆ ast_variable_retrieve()

const char * ast_variable_retrieve ( struct ast_config config,
const char *  category,
const char *  variable 
)

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

871{
872 struct ast_variable *v;
873 const char *match = NULL;
874
875 /* We can't return as soon as we find a match, because if a config section overrides
876 * something specified in a template, then the actual effective value is the last
877 * one encountered, not the first one.
878 * (This is like using the -1 index for the AST_CONFIG function.)
879 * Also see ast_variable_find_last_in_list
880 */
881
882 if (category) {
883 for (v = ast_variable_browse(config, category); v; v = v->next) {
884 if (!strcasecmp(variable, v->name)) {
885 match = v->value;
886 }
887 }
888 } else {
889 struct ast_category *cat;
890
891 for (cat = config->root; cat; cat = cat->next) {
892 for (v = cat->root; v; v = v->next) {
893 if (!strcasecmp(variable, v->name)) {
894 match = v->value;
895 }
896 }
897 }
898 }
899
900 return match;
901}
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)

References ast_variable_browse(), config, match(), ast_variable::name, ast_variable::next, ast_category::next, NULL, ast_category::root, and ast_variable::value.

Referenced by __queues_show(), actual_load_config(), advanced_options(), ast_config_option(), ast_init_logger_for_socket_console(), AST_TEST_DEFINE(), check_for_old_config(), conf_exec(), config_module(), directory_exec(), festival_exec(), find_realtime(), forward_message(), get_defaults(), iax_template_parse(), init_acf_query(), init_logger_chain(), initialize_cc_devstate_map_helper(), initialize_cc_max_requests(), internal_aco_type_find(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config(), load_config_meetme(), load_indications(), load_module(), load_module(), load_module(), load_module(), load_mysql_config(), load_realtime_musiconhold(), load_realtime_queues(), load_realtime_rules(), load_tech_calendars(), load_users(), loader_config_init(), make_email_file(), mbl_load_adapter(), mbl_load_device(), message_range_and_existence_check(), named_acl_find_realtime(), notify_new_message(), odbc_load_module(), parse_config(), parse_config(), pbx_load_config(), play_message(), prep_email_sub_vars(), private_enum_init(), process_my_load_module(), queue_rules_set_global_params(), queue_set_global_params(), read_password_from_file(), realtime_directory(), realtime_switch_common(), reload(), reload_config(), reload_followme(), reload_single_queue(), rt_handle_member_record(), rtp_reload(), search_directory(), set_config(), set_member_value(), setup_dahdi_int(), sla_build_station(), sla_build_trunk(), sla_load_config(), tds_load_module(), tds_load_module(), vm_change_password(), vm_forwardoptions(), vm_msg_forward(), vm_msg_play(), and vm_msg_snapshot_create().

◆ ast_variable_retrieve_filtered()

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 903 of file main/config.c.

905{
906 struct ast_category *cat = NULL;
907 const char *value;
908
909 while ((cat = ast_category_browse_filtered(config, category, cat, filter))) {
910 value = ast_variable_find(cat, variable);
911 if (value) {
912 return value;
913 }
914 }
915
916 return NULL;
917}
const char * ast_variable_find(const struct ast_category *category, const char *variable)
Gets a variable value from a specific category structure by name.
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.

References ast_category_browse_filtered(), ast_variable_find(), config, filter(), NULL, and value.

◆ ast_variable_update()

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 1646 of file main/config.c.

1648{
1649 struct ast_variable *cur, *prev = NULL, *newer = NULL;
1650 struct ast_variable *matchcur = NULL, *matchprev = NULL;
1651
1652 /* Find the last match. See comments in ast_variable_retrieve,
1653 * but this ensures updating config sections that inherit from
1654 * templates works properly. */
1655 for (cur = category->root; cur; prev = cur, cur = cur->next) {
1656 if (strcasecmp(cur->name, variable) || (!ast_strlen_zero(match) && strcasecmp(cur->value, match))) {
1657 /* Not the same variable,
1658 * or its value doesn't match. */
1659 continue;
1660 }
1661 matchprev = prev;
1662 matchcur = cur;
1663 }
1664
1665 if (!matchcur) {
1666 /* Could not find variable to update */
1667 return -1;
1668 }
1669
1670 /* Restore pointers from the matching var */
1671 prev = matchprev;
1672 cur = matchcur;
1673
1674 if (!(newer = ast_variable_new(variable, value, cur->file))) {
1675 return -1;
1676 }
1677
1678 ast_variable_move(newer, cur);
1679 newer->object = newer->object || object;
1680
1681 /* Replace the old node in the list with the new node. */
1682 newer->next = cur->next;
1683 if (prev) {
1684 prev->next = newer;
1685 } else {
1686 category->root = newer;
1687 }
1688 if (category->last == cur) {
1689 category->last = newer;
1690 }
1691
1693 return 0;
1694}

References ast_strlen_zero(), ast_variable_destroy(), ast_variable_move(), ast_variable_new, ast_variable::file, ast_category::last, match(), ast_variable::name, ast_variable::next, ast_category::next, NULL, ast_category::prev, ast_category::root, ast_variable::value, and value.

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

◆ ast_variables_destroy()

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 1260 of file extconf.c.

1261{
1262 struct ast_variable *vn;
1263
1264 while (v) {
1265 vn = v;
1266 v = v->next;
1267 free(vn);
1268 }
1269}

References ast_variable_destroy(), free(), ast_variable::next, and var.

Referenced by __init_manager(), aco_set_defaults(), action_messagesend(), action_originate(), add_message_id(), aeap_cli_show(), announce_to_dial(), app_notify(), ari_conf_owc_detect_changes(), ast_aeap_client_configs_get(), ast_ari_asterisk_update_object(), ast_ari_callback(), ast_ari_channels_create(), ast_ari_channels_external_media(), 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_ari_invoke(), ast_category_destroy(), ast_category_empty(), ast_destroy_realtime(), ast_geoloc_eprofile_refresh_location(), ast_geoloc_eprofile_to_uri(), ast_http_get_cookies(), ast_http_manid_from_vars(), ast_json_to_ast_variables(), ast_load_realtime(), ast_load_realtime_all(), ast_load_realtime_multientry(), ast_sip_cli_print_sorcery_objectset(), ast_sip_sorcery_object_to_ami(), 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_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), ast_update2_realtime(), ast_update_realtime(), ast_var_channel_types(), ast_var_channel_types_table(), ast_variable_list_from_quoted_string(), ast_variables_dup(), ast_websocket_client_get_field_diff(), auth_http_callback(), calendar_destructor(), can_reuse_registration(), check_expiration_thread(), cli_contact_get_container(), cli_realtime_load(), conf_run(), config_object_cli_show(), copy_plain_file(), create_mwi_subscriptions(), curl_header_data_free(), destroy_dahdi_pvt(), destroy_fast_originate_helper(), dup_vars(), endpoint_destructor(), fields_handler(), find_conf_realtime(), find_load_queue_rt_friendly(), find_realtime(), find_user_realtime(), find_user_realtime(), free_entry(), free_outgoing(), free_user(), function_realtime_read(), function_realtime_readdestroy(), generic_http_callback(), geoloc_eprofile_destructor(), geoloc_eprofile_resolve_varlist(), geoloc_eprofile_to_intermediate(), geoloc_location_destructor(), geoloc_profile_destructor(), get_multiple_fields_as_var_list(), get_object_variables(), handle_aor(), handle_auth(), handle_endpoint(), handle_export_primitives(), handle_identify(), handle_phoneprov(), handle_pjproject_show_log_mappings(), handle_registrations(), handle_showchan(), handle_uri(), http_request_headers_get(), httpd_process_request(), httpstatus_callback(), incoming_ws_http_callback(), ldap_loadentry(), leave_queue(), load_realtime_musiconhold(), local_ast_moh_start(), manager_free_user(), manager_send_response(), mkintf(), notify_ami_channel_data_destroy(), notify_ami_data_destroy(), notify_ami_uri_data_destroy(), object_type_loaded_observer(), originate_exec(), outbound_session_handler_thread(), pjsip_aor_function_read(), pjsip_contact_function_read(), pjsip_endpoint_function_read(), process_dahdi(), publication_resource_destroy(), pvt_destructor(), queue_function_queuegetchannel(), queue_function_queuewaitingcount(), realtime_arguments_to_fields(), realtime_arguments_to_fields2(), realtime_canmatch(), realtime_common(), realtime_exec(), realtime_exists(), realtime_ldap_base(), realtime_ldap_base_ap(), realtime_ldap_result_to_vars(), realtime_matchmore(), realtime_odbc(), realtime_peer(), realtime_user(), realtimefield_read(), request_destroy(), return_sorcery_object(), row_to_varlist(), rt_extend_conf(), session_destructor(), sip_aor_to_ami(), socket_process_helper(), sorcery_astdb_filter_objectset(), sorcery_astdb_retrieve_fields_common(), sorcery_astdb_retrieve_id(), sorcery_astdb_retrieve_prefix(), sorcery_astdb_retrieve_regex(), sorcery_config_destructor(), sorcery_config_fields_cmp(), sorcery_function_read(), sorcery_is_criteria_met(), sorcery_memory_cache_fields_cmp(), sorcery_memory_cached_object_destructor(), sorcery_memory_fields_cmp(), sorcery_object_destructor(), sorcery_realtime_create(), sorcery_realtime_filter_objectset(), sorcery_realtime_retrieve_fields(), sorcery_realtime_retrieve_id(), sorcery_realtime_retrieve_multiple(), sorcery_realtime_retrieve_prefix(), sorcery_realtime_retrieve_regex(), sorcery_realtime_update(), speech_aeap_engine_create(), table_configs_free(), test_sorcery_object_destroy(), test_sorcery_transform(), transport_apply(), update_ldap(), user_destructor(), var_list_from_confidence(), var_list_from_loc_info(), var_list_from_node(), and websocket_client_handshake().

◆ ast_variables_dup()

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 630 of file main/config.c.

631{
632 struct ast_variable *cloned;
633 struct ast_variable *tmp;
634
635 if (!(cloned = ast_variable_new(var->name, var->value, var->file))) {
636 return NULL;
637 }
638
639 tmp = cloned;
640
641 while ((var = var->next)) {
642 if (!(tmp->next = ast_variable_new(var->name, var->value, var->file))) {
643 ast_variables_destroy(cloned);
644 return NULL;
645 }
646 tmp = tmp->next;
647 }
648
649 return cloned;
650}

References ast_variable_new, ast_variables_destroy(), ast_variable::next, NULL, and var.

Referenced by action_originate(), ast_ari_callback(), ast_config_copy(), authenticate(), handle_registrations(), jim_handler(), jim_vl(), realtime_sorcery(), realtime_sorcery_multi(), realtime_sorcery_store(), realtime_sorcery_update(), set_var_to_vl(), and sorcery_extended_fields_handler().

◆ ast_variables_match()

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 936 of file main/config.c.

937{
938 char *op;
939
940 if (left == right) {
941 return 1;
942 }
943
944 if (!(left && right)) {
945 return 0;
946 }
947
948 op = strrchr(right->name, ' ');
949 if (op) {
950 op++;
951 }
952
953 return ast_strings_match(left->value, op ? ast_strdupa(op) : NULL, right->value);
954}
int ast_strings_match(const char *left, const char *op, const char *right)
Compares 2 strings using realtime-style operators.
Definition strings.c:260

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

Referenced by ast_variable_lists_match().

◆ ast_variables_reverse()

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 652 of file main/config.c.

653{
654 struct ast_variable *var1, *var2;
655
656 var1 = var;
657
658 if (!var1 || !var1->next) {
659 return var1;
660 }
661
662 var2 = var1->next;
663 var1->next = NULL;
664
665 while (var2) {
666 struct ast_variable *next = var2->next;
667
668 var2->next = var1;
669 var1 = var2;
670 var2 = next;
671 }
672
673 return var1;
674}

References ast_variable::next, NULL, and var.

Referenced by astman_get_variables_order().

◆ register_config_cli()

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 4503 of file main/config.c.

4504{
4506 /* This is separate from the module load so cleanup can happen very late. */
4508 return 0;
4509}
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition clicompat.c:19
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition cli.h:265
static struct ast_cli_entry cli_config[]
static void config_shutdown(void)
#define ARRAY_LEN(a)
Definition utils.h:703

References ARRAY_LEN, ast_cli_register_multiple, ast_register_cleanup(), cli_config, and config_shutdown().

Referenced by asterisk_daemon().