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

Configuration File Parser. More...

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

Typedefs

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

Enumerations

enum  { CONFIG_FLAG_WITHCOMMENTS = (1 << 0), CONFIG_FLAG_FILEUNCHANGED = (1 << 1), CONFIG_FLAG_NOCACHE = (1 << 2), CONFIG_FLAG_NOREALTIME = (1 << 3) }
 
enum  ast_parse_flags {
  PARSE_TYPE = 0x000f, PARSE_INT32 = 0x0001, PARSE_UINT32 = 0x0002, PARSE_DOUBLE = 0x0003,
  PARSE_TIMELEN = 0x0006, PARSE_ADDR = 0x000e, PARSE_INADDR = 0x000f, PARSE_DEFAULT = 0x0010,
  PARSE_IN_RANGE = 0x0020, PARSE_OUT_RANGE = 0x0040, PARSE_RANGE_DEFAULTS = 0x0080, PARSE_PORT_MASK = 0x0300,
  PARSE_PORT_IGNORE = 0x0100, PARSE_PORT_REQUIRE = 0x0200, PARSE_PORT_FORBID = 0x0300
}
 Support code to parse config file arguments. More...
 
enum  config_hook_flags { butt }
 Flags that affect the behaviour of config hooks. 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 *cat)
 Appends a category to a config. More...
 
char * ast_category_browse (struct ast_config *config, const char *prev_name)
 Browse categories. More...
 
struct ast_categoryast_category_browse_filtered (struct ast_config *config, const char *category_name, struct ast_category *prev, const char *filter)
 Browse categories with filters. More...
 
struct ast_categoryast_category_delete (struct ast_config *cfg, struct ast_category *category)
 Delete a category. More...
 
void ast_category_destroy (struct ast_category *cat)
 
struct ast_variableast_category_detach_variables (struct ast_category *cat)
 
int ast_category_empty (struct ast_category *category)
 Removes and destroys all variables in a category. More...
 
int ast_category_exist (const struct ast_config *config, const char *category_name, const char *filter)
 Check for category duplicates. More...
 
struct ast_variableast_category_first (struct ast_category *cat)
 given a pointer to a category, return the root variable. More...
 
struct ast_categoryast_category_get (const struct ast_config *config, const char *category_name, const char *filter)
 Retrieve a category if it exists. More...
 
const char * ast_category_get_name (const struct ast_category *category)
 Return the name of the category. More...
 
struct ast_strast_category_get_templates (const struct ast_category *category)
 Return the template names this category inherits from. More...
 
int ast_category_inherit (struct ast_category *existing, const struct ast_category *base)
 Applies base (template) to category. More...
 
int ast_category_insert (struct ast_config *config, struct ast_category *cat, const char *match)
 Inserts new category. More...
 
int ast_category_is_template (const struct ast_category *category)
 Check if category is a template. More...
 
struct ast_categoryast_category_new (const char *name, const char *in_file, int lineno)
 Create a category. More...
 
struct ast_categoryast_category_new_template (const char *name, const char *in_file, int lineno)
 Create a category making it a template. More...
 
void ast_category_rename (struct ast_category *cat, const char *name)
 
struct ast_variableast_category_root (struct ast_config *config, char *cat)
 returns the root ast_variable of a config More...
 
int ast_check_realtime (const char *family)
 Check if realtime engine is configured for family. More...
 
struct ast_configast_config_copy (const struct ast_config *orig)
 Copies the contents of one ast_config into another. More...
 
void ast_config_destroy (struct ast_config *config)
 Destroys a config. More...
 
int ast_config_engine_deregister (struct ast_config_engine *del)
 Deregister config engine. More...
 
int ast_config_engine_register (struct ast_config_engine *newconfig)
 Register config engine. More...
 
struct ast_categoryast_config_get_current_category (const struct ast_config *cfg)
 Retrieve the current category name being built. More...
 
int ast_config_hook_register (const char *name, const char *filename, const char *module, enum config_hook_flags flags, config_hook_cb hook)
 Register a config hook for a particular file and module. More...
 
void ast_config_hook_unregister (const char *name)
 Unregister a config hook. More...
 
struct ast_configast_config_internal_load (const char *configfile, struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl_file, const char *who_asked)
 
struct ast_configast_config_load2 (const char *filename, const char *who_asked, struct ast_flags flags)
 Load a config file. More...
 
struct ast_configast_config_new (void)
 Create a new base configuration structure. More...
 
const char * ast_config_option (struct ast_config *cfg, const char *cat, const char *var)
 Retrieve a configuration variable within the configuration set. More...
 
void ast_config_set_current_category (struct ast_config *cfg, const struct ast_category *cat)
 Set the category within the configuration as being current. More...
 
void ast_config_sort_categories (struct ast_config *config, int descending, int(*comparator)(struct ast_category *p, struct ast_category *q))
 Sorts categories in a config in the order of a numerical value contained within them. More...
 
int ast_config_text_file_save (const char *filename, const struct ast_config *cfg, const char *generator)
 Save a config text file preserving the pre 13.2 behavior. More...
 
int ast_config_text_file_save2 (const char *filename, const struct ast_config *cfg, const char *generator, uint32_t flags)
 Save a config text file. More...
 
int ast_destroy_realtime (const char *family, const char *keyfield, const char *lookup,...) attribute_sentinel
 Destroy realtime configuration. More...
 
int ast_destroy_realtime_fields (const char *family, const char *keyfield, const char *lookup, const struct ast_variable *fields)
 Destroy realtime configuration. More...
 
struct ast_config_includeast_include_find (struct ast_config *conf, const char *included_file)
 
struct ast_config_includeast_include_new (struct ast_config *conf, const char *from_file, const char *included_file, int is_exec, const char *exec_file, int from_lineno, char *real_included_file_name, int real_included_file_name_size)
 
void ast_include_rename (struct ast_config *conf, const char *from_file, const char *to_file)
 
struct ast_variableast_load_realtime (const char *family,...) attribute_sentinel
 
struct ast_variableast_load_realtime_all (const char *family,...) attribute_sentinel
 
struct ast_variableast_load_realtime_all_fields (const char *family, const struct ast_variable *fields)
 
struct ast_variableast_load_realtime_fields (const char *family, const struct ast_variable *fields)
 Retrieve realtime configuration. More...
 
struct ast_configast_load_realtime_multientry (const char *family,...) attribute_sentinel
 Retrieve realtime configuration. More...
 
struct ast_configast_load_realtime_multientry_fields (const char *family, const struct ast_variable *fields)
 Retrieve realtime configuration. More...
 
int ast_parse_arg (const char *arg, enum ast_parse_flags flags, void *result,...)
 The argument parsing routine. More...
 
int ast_realtime_append_mapping (const char *name, const char *driver, const char *database, const char *table, int priority)
 Add an explicit mapping for a family. More...
 
char * ast_realtime_decode_chunk (char *chunk)
 Remove standard encoding from realtime values, which ensures that a semicolon embedded within a single value is not treated upon retrieval as multiple values. More...
 
int ast_realtime_enabled (void)
 Check if there's any realtime engines loaded. More...
 
char * ast_realtime_encode_chunk (struct ast_str **dest, ssize_t maxlen, const char *chunk)
 Encodes a chunk of data for realtime. More...
 
int ast_realtime_is_mapping_defined (const char *family)
 Determine if a mapping exists for a given family. More...
 
int ast_realtime_require_field (const char *family,...) attribute_sentinel
 Inform realtime what fields that may be stored. More...
 
int ast_rq_is_int (require_type type)
 Check if require type is an integer type. More...
 
int ast_store_realtime (const char *family,...) attribute_sentinel
 Create realtime configuration. More...
 
int ast_store_realtime_fields (const char *family, const struct ast_variable *fields)
 Create realtime configuration. More...
 
int ast_unload_realtime (const char *family)
 Release any resources cached for a realtime family. More...
 
int ast_update2_realtime (const char *family,...) attribute_sentinel
 Update realtime configuration. More...
 
int ast_update2_realtime_fields (const char *family, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields)
 Update realtime configuration. More...
 
int ast_update_realtime (const char *family, const char *keyfield, const char *lookup,...) attribute_sentinel
 Update realtime configuration. More...
 
int ast_update_realtime_fields (const char *family, const char *keyfield, const char *lookup, const struct ast_variable *fields)
 Update realtime configuration. More...
 
void ast_variable_append (struct ast_category *category, struct ast_variable *variable)
 
struct ast_variableast_variable_browse (const struct ast_config *config, const char *category_name)
 
struct ast_variableast_variable_browse_filtered (const struct ast_config *config, const char *category_name, const char *filter)
 Browse variables. More...
 
int ast_variable_delete (struct ast_category *category, const char *variable, const char *match, const char *line)
 
const char * ast_variable_find (const struct ast_category *category, const char *variable)
 Gets a variable value from a specific category structure by name. More...
 
const char * ast_variable_find_in_list (const struct ast_variable *list, const char *variable)
 Gets the value of a variable from a variable list by name. More...
 
const char * ast_variable_find_last_in_list (const struct ast_variable *list, const char *variable)
 Gets the value of the LAST occurrence of a variable from a variable list. More...
 
const struct ast_variableast_variable_find_variable_in_list (const struct ast_variable *list, const char *variable_name)
 Gets a variable from a variable list by name. More...
 
void ast_variable_insert (struct ast_category *category, struct ast_variable *variable, const char *line)
 
struct ast_variableast_variable_list_append_hint (struct ast_variable **head, struct ast_variable *search_hint, struct ast_variable *new_var)
 Appends a variable list to the end of another list. More...
 
int ast_variable_list_replace (struct ast_variable **head, struct ast_variable *replacement)
 Replace a variable in the given list with a new value. More...
 
struct ast_variableast_variable_list_sort (struct ast_variable *head)
 Performs an in-place sort on the variable list by ascending name. More...
 
int ast_variable_lists_match (const struct ast_variable *left, const struct ast_variable *right, int exact_match)
 Tests 2 variable lists to see if they match. More...
 
const char * ast_variable_retrieve (struct ast_config *config, const char *category, const char *variable)
 
const char * ast_variable_retrieve_filtered (struct ast_config *config, const char *category, const char *variable, const char *filter)
 Gets a variable by context and variable names. More...
 
int ast_variable_update (struct ast_category *category, const char *variable, const char *value, const char *match, unsigned int object)
 Update variable value within a config. More...
 
void ast_variables_destroy (struct ast_variable *var)
 Free variable list. More...
 
struct ast_variableast_variables_dup (struct ast_variable *var)
 Duplicate variable list. More...
 
int ast_variables_match (const struct ast_variable *left, const struct ast_variable *right)
 Tests 2 variable values to see if they match. More...
 
struct ast_variableast_variables_reverse (struct ast_variable *var)
 Reverse a variable list. More...
 
int register_config_cli (void)
 Exposed initialization method for core process. More...
 

Detailed Description

Configuration File Parser.

Definition in file include/asterisk/config.h.

Macro Definition Documentation

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

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

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

Referenced by add_cfg_entry(), add_rt_multi_cfg_entry(), config_curl(), config_ldap(), config_mysql(), config_odbc(), config_pgsql(), realtime_directory(), and static_realtime_cb().

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

Referenced by aco_process_config(), adsi_load(), advanced_options(), AST_TEST_DEFINE(), conf_exec(), config_function_read(), config_load(), config_module(), directory_exec(), festival_exec(), find_conf(), forward_message(), get_defaults(), handle_cli_dialplan_save(), ineligible_configuration(), load_config(), load_config_meetme(), load_module(), load_moh_classes(), load_odbc_config(), load_pktccops_config(), load_values_config(), make_email_file(), mbl_load_config(), message_range_and_existence_check(), my_load_module(), notify_new_message(), odbc_load_module(), osp_load(), parse_config(), pbx_load_config(), pbx_load_users(), play_message(), prep_email_sub_vars(), process_config(), read_password_from_file(), realtime_directory(), reload(), reload_config(), reload_followme(), reload_module(), reload_queue_rules(), reload_queues(), set_config(), setup_dahdi_int(), sla_load_config(), smdi_load(), tds_load_module(), vm_change_password(), vm_forwardoptions(), vm_msg_forward(), vm_msg_play(), and vm_msg_snapshot_create().

◆ ast_variable_list_append

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

◆ ast_variable_new

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

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

Referenced by __init_manager(), aco_set_defaults(), add_cfg_entry(), add_message_id(), add_rt_cfg_entry(), add_rt_multi_cfg_entry(), add_var(), announce_to_dial(), append_row_to_cfg(), append_variable(), ast_ari_asterisk_update_object(), ast_ari_invoke(), ast_channeltype_list(), ast_http_get_post_vars(), ast_include_rename(), ast_json_to_ast_variables(), ast_sorcery_changeset_create(), ast_sorcery_object_set_extended(), ast_stream_get_metadata_list(), ast_stream_set_metadata(), AST_TEST_DEFINE(), ast_variable_update(), ast_variables_dup(), build_calendar(), build_cfg(), build_user(), check_access(), check_expiration_thread(), cli_contact_get_container(), config_curl(), config_ldap(), config_mysql(), config_odbc(), config_pgsql(), contact_to_var_list(), copy_vars(), create_mwi_subscriptions(), create_vmaccount(), dup_vars(), fields_handler(), get_single_field_as_var_list(), handle_registrations(), handle_updates(), handle_uri(), http_request_headers_get(), iax_parse_ies(), inherit_channel_vars_from_id(), jack_handler(), ldap_table_config_add_attribute(), load_realtime_musiconhold(), localnet_to_vl_append(), man_do_variable_value(), manager_sipnotify(), match_to_var_list_append(), mkintf(), object_type_loaded_observer(), originate_exec(), outbound_auths_to_var_list(), parse_cookies(), process_dahdi(), process_text_line(), realtime_arguments_to_fields(), realtime_arguments_to_fields2(), realtime_curl(), realtime_directory(), realtime_ldap_entry_to_var(), realtime_ldap_result_to_vars(), realtime_multi_curl(), realtime_multi_mysql(), realtime_multi_odbc(), realtime_multi_pgsql(), realtime_mysql(), realtime_odbc(), realtime_pgsql(), realtime_sorcery_update(), resource_event_handler(), row_to_varlist(), set_var_handler(), sip_cli_notify(), sorcery_config_open(), sorcery_realtime_create(), sorcery_realtime_retrieve_id(), sorcery_realtime_retrieve_multiple(), sorcery_realtime_retrieve_prefix(), sorcery_realtime_retrieve_regex(), static_realtime_cb(), test_sorcery_copy(), test_sorcery_diff(), test_sorcery_regex_fields(), test_sorcery_transform(), update_ldap(), variable_clone(), variable_list_append(), verify_user_event_fields(), vm_change_password(), and write_password_to_file().

◆ CONFIG_STATUS_FILEINVALID

#define CONFIG_STATUS_FILEINVALID   (void *)-2

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

Referenced by __ast_http_load(), __ast_http_post_load(), __ast_sorcery_apply_config(), __init_manager(), _dsp_init(), aco_process_config(), action_getconfig(), action_getconfigjson(), action_listcategories(), action_updateconfig(), adsi_load(), ast_config_internal_load(), ast_config_load2(), ast_init_logger_for_socket_console(), ast_xmldoc_load_documentation(), conf_exec(), config_function_read(), config_load(), config_module(), config_text_file_load(), directory_exec(), do_reload(), festival_exec(), find_conf(), forward_message(), get_defaults(), iax_provision_reload(), init_logger_chain(), initialize_cc_devstate_map(), initialize_cc_max_requests(), load_asterisk_conf(), load_config(), load_config_meetme(), load_indications(), load_module(), load_moh_classes(), load_odbc_config(), load_values_config(), loader_config_init(), message_range_and_existence_check(), misdn_cfg_init(), my_load_module(), notify_new_message(), object_type_loaded_observer(), odbc_load_module(), osp_load(), parse_config(), pbx_load_config(), private_enum_init(), process_config(), read_pjproject_startup_options(), realtime_directory(), reload(), reload_config(), reload_followme(), reload_module(), reload_queue_rules(), reload_queues(), rtp_reload(), run_startup_commands(), set_config(), setup_dahdi_int(), sla_load_config(), smdi_load(), sorcery_config_internal_load(), tds_load_module(), valid_config(), vm_forwardoptions(), vm_msg_forward(), vm_msg_play(), and vm_msg_snapshot_create().

◆ CONFIG_STATUS_FILEMISSING

#define CONFIG_STATUS_FILEMISSING   (void *)0

◆ CONFIG_STATUS_FILEUNCHANGED

#define CONFIG_STATUS_FILEUNCHANGED   (void *)-1

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

Referenced by store_config_core().

◆ CV_DSTR

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

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

◆ CV_END

#define CV_END   } while (0)

close a variable parsing block

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

Referenced by store_config_core(), and store_config_tone_zone().

◆ CV_F

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

call a generic function if the name matches.

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

Referenced by store_config_core(), and store_config_tone_zone().

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

Referenced by store_config_core(), and store_config_tone_zone().

◆ CV_STR

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

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

Referenced by store_config_core(), and store_config_tone_zone().

◆ CV_STRFIELD

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

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

Referenced by store_config_core().

◆ CV_UINT

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

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

Referenced by store_config_core().

Typedef Documentation

◆ config_hook_cb

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

Definition at line 1035 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. */
43  CONFIG_FLAG_FILEUNCHANGED = (1 << 1),
44  /*! Don't attempt to cache mtime on this config file. */
45  CONFIG_FLAG_NOCACHE = (1 << 2),
46  /*! Don't attempt to load from realtime (typically called from a realtime driver dependency) */
47  CONFIG_FLAG_NOREALTIME = (1 << 3),
48 };

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

1080  {
1081  /* low 4 bits of flags are used for the operand type */
1082  PARSE_TYPE = 0x000f,
1083  /* numeric types, with optional default value and bound checks.
1084  * Additional arguments are passed by value.
1085  */
1086  PARSE_INT32 = 0x0001,
1087  PARSE_UINT32 = 0x0002,
1088  PARSE_DOUBLE = 0x0003,
1089 #if 0 /* not supported yet */
1090  PARSE_INT16 = 0x0004,
1091  PARSE_UINT16 = 0x0005,
1092 #endif
1093 
1094  /* Returns an int processed by ast_app_parse_timelen.
1095  * The first argument is an enum ast_timelen value (required).
1096  */
1097  PARSE_TIMELEN = 0x0006,
1098 
1099  /* Returns a struct ast_sockaddr, with optional default value
1100  * (passed by reference) and port handling (accept, ignore,
1101  * require, forbid). The format is 'ipaddress[:port]'. IPv6 address
1102  * literals need square brackets around them if a port is specified.
1103  */
1104  PARSE_ADDR = 0x000e,
1105 
1106  /* Returns a struct sockaddr_in, with optional default value
1107  * (passed by reference) and port handling (accept, ignore,
1108  * require, forbid). The format is 'host.name[:port]'
1109  */
1110  PARSE_INADDR = 0x000f,
1111 
1112  /* Other data types can be added as needed */
1113 
1114  /* If PARSE_DEFAULT is set, next argument is a default value
1115  * which is returned in case of error. The argument is passed
1116  * by value in case of numeric types, by reference in other cases.
1117  */
1118  PARSE_DEFAULT = 0x0010, /* assign default on error */
1119 
1120  /* Request a range check, applicable to numbers. Two additional
1121  * arguments are passed by value, specifying the low-high end of
1122  * the range (inclusive). An error is returned if the value
1123  * is outside or inside the range, respectively.
1124  */
1125  PARSE_IN_RANGE = 0x0020, /* accept values inside a range */
1126  PARSE_OUT_RANGE = 0x0040, /* accept values outside a range */
1127  PARSE_RANGE_DEFAULTS = 0x0080, /* default to range min/max on range error */
1128 
1129  /* Port handling, for ast_sockaddr. accept/ignore/require/forbid
1130  * port number after the hostname or address.
1131  */
1132  PARSE_PORT_MASK = 0x0300, /* 0x000: accept port if present */
1133  PARSE_PORT_IGNORE = 0x0100, /* 0x100: ignore port if present */
1134  PARSE_PORT_REQUIRE = 0x0200, /* 0x200: require port number */
1135  PARSE_PORT_FORBID = 0x0300, /* 0x100: forbid port number */
1136 };

◆ config_hook_flags

Flags that affect the behaviour of config hooks.

Enumerator
butt 

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

1025  {
1026  butt,
1027 };

◆ 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 };

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

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

289 {
290  struct ast_variable *variable;
291  int name_len = strlen(name) + 1;
292  int val_len = strlen(value) + 1;
293  int fn_len = strlen(filename) + 1;
294 
295  /* Ensure a minimum length in case the filename is changed later. */
296  if (fn_len < MIN_VARIABLE_FNAME_SPACE) {
297  fn_len = MIN_VARIABLE_FNAME_SPACE;
298  }
299 
300  variable = __ast_calloc(1, fn_len + name_len + val_len + sizeof(*variable),
301  file, lineno, func);
302  if (variable) {
303  char *dst = variable->stuff; /* writable space starts here */
304 
305  /* Put file first so ast_include_rename() can calculate space available. */
306  variable->file = strcpy(dst, filename);
307  dst += fn_len;
308  variable->name = strcpy(dst, name);
309  dst += name_len;
310  variable->value = strcpy(dst, value);
311  }
312  return variable;
313 }
void * __ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func) attribute_malloc
Definition: astmm.c:1635
Structure for variables, used for configurations and for channel variables.
int value
Definition: syslog.c:37
char stuff[0]
Contents of file, name, and value in that order stuffed here.
static const char name[]
Definition: cdr_mysql.c:74
#define MIN_VARIABLE_FNAME_SPACE
Definition: main/config.c:73

◆ ast_category_append()

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

Appends a category to a config.

Parameters
configwhich config to use
catcategory to insert

Definition at line 2835 of file extconf.c.

References ast_config::current, ast_category::include_level, ast_config::include_level, ast_config::last, ast_category::next, NULL, ast_category::prev, and ast_config::root.

Referenced by add_cfg_entry(), add_rt_multi_cfg_entry(), append_row_to_cfg(), ast_config_copy(), AST_TEST_DEFINE(), build_cfg(), config_curl(), config_ldap(), config_mysql(), config_odbc(), config_pgsql(), handle_updates(), process_text_line(), realtime_directory(), realtime_multi_curl(), realtime_multi_ldap(), realtime_multi_mysql(), realtime_multi_odbc(), realtime_multi_pgsql(), realtime_sorcery_multi(), realtime_sorcery_store(), realtime_sorcery_update(), static_realtime_cb(), and write_password_to_file().

2836 {
2837  if (config->last)
2838  config->last->next = category;
2839  else
2840  config->root = category;
2841  config->last = category;
2842  config->current = category;
2843 }
struct ast_category * next
Definition: main/config.c:246
struct ast_category * last
Definition: main/config.c:253
struct ast_category * current
Definition: main/config.c:254
struct ast_category * root
Definition: main/config.c:251

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

References ast_config::last_browse, ast_category::name, ast_category::next, next_available_category(), NULL, and ast_config::root.

Referenced by __init_manager(), __queues_show(), actual_load_config(), ast_cli_perms_init(), AST_TEST_DEFINE(), complete_sip_notify(), conf_exec(), config_load(), find_queue_by_name_rt(), find_realtime(), get_insecure_variable_from_config(), get_insecure_variable_from_sipregs(), iax_provision_reload(), internal_process_ast_config(), load_config(), load_indications(), load_module(), load_moh_classes(), load_odbc_config(), load_pktccops_config(), load_realtime_musiconhold(), load_realtime_rules(), load_tech_calendars(), load_users(), mbl_load_config(), misdn_cfg_init(), named_acl_find_realtime(), osp_load(), parse_config(), pbx_load_config(), pbx_load_users(), realtime_directory(), realtime_sorcery(), realtime_sorcery_multi(), realtime_switch_common(), register_realtime_peers_with_callbackextens(), reload(), reload_config(), reload_followme(), reload_queue_rules(), reload_queues(), search_directory(), search_directory_sub(), set_config(), set_member_value(), setup_dahdi_int(), show_users_realtime(), sla_load_config(), test_config_validity(), update_realtime_members(), and vm_change_password().

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

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

References ast_category::next, next_available_category(), and ast_config::root.

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

1337 {
1338  struct ast_category *cat;
1339 
1340  if (!prev) {
1341  prev = config->root;
1342  } else {
1343  prev = prev->next;
1344  }
1345 
1346  cat = next_available_category(prev, category_name, filter);
1347 
1348  return cat;
1349 }
struct ast_category * next
Definition: main/config.c:246
static struct ast_category * next_available_category(struct ast_category *cat, const char *name, const char *filter)
Definition: main/config.c:1148
struct ast_category * root
Definition: main/config.c:251
static int filter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:709

◆ ast_category_delete()

struct ast_category* ast_category_delete ( struct ast_config cfg,
struct ast_category category 
)

Delete a category.

Parameters
configwhich config to use
categorycategory 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 1478 of file main/config.c.

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

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

1480 {
1481  struct ast_category *prev;
1482 
1483  if (!config || !category) {
1484  return NULL;
1485  }
1486 
1487  if (category->prev) {
1488  category->prev->next = category->next;
1489  } else {
1490  config->root = category->next;
1491  }
1492 
1493  if (category->next) {
1494  category->next->prev = category->prev;
1495  } else {
1496  config->last = category->prev;
1497  }
1498 
1499  prev = category->prev;
1500 
1501  if (config->last_browse == category) {
1502  config->last_browse = prev;
1503  }
1504 
1505  ast_category_destroy(category);
1506 
1507  return prev;
1508 }
struct ast_category * next
Definition: main/config.c:246
char * config
Definition: conf2ael.c:66
struct ast_category * prev
Definition: main/config.c:244
#define NULL
Definition: resample.c:96
void ast_category_destroy(struct ast_category *cat)
Definition: main/config.c:1122

◆ ast_category_destroy()

static void ast_category_destroy ( struct ast_category cat)

Definition at line 2847 of file extconf.c.

References ast_comment_destroy(), ast_destroy_template_list(), ast_free, ast_variables_destroy(), ast_category::file, ast_category::last, NULL, ast_category::precomments, ast_category::root, ast_category::sameline, and ast_category::trailing.

Referenced by add_cfg_entry(), ast_category_delete(), ast_config_destroy(), handle_updates(), new_category(), process_text_line(), realtime_multi_odbc(), static_realtime_cb(), and write_password_to_file().

2848 {
2850  if (cat->file)
2851  free(cat->file);
2852 
2853  free(cat);
2854 }
char * file
The file name from whence this declaration was read.
Definition: main/config.c:233
void free()
struct ast_variable * root
Definition: main/config.c:240
static void ast_variables_destroy(struct ast_variable *v)
Definition: extconf.c:1263

◆ ast_category_detach_variables()

struct ast_variable* ast_category_detach_variables ( struct ast_category cat)

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

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

Referenced by realtime_switch_common(), and sorcery_realtime_retrieve_multiple().

1352 {
1353  struct ast_variable *v;
1354 
1355  v = cat->root;
1356  cat->root = NULL;
1357  cat->last = NULL;
1358 
1359  return v;
1360 }
Structure for variables, used for configurations and for channel variables.
#define NULL
Definition: resample.c:96
struct ast_variable * root
Definition: main/config.c:240
struct ast_variable * last
Definition: main/config.c:242

◆ 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 categopry is NULL

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

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

Referenced by AST_TEST_DEFINE(), and handle_updates().

1511 {
1512  if (!category) {
1513  return -1;
1514  }
1515 
1516  ast_variables_destroy(category->root);
1517  category->root = NULL;
1518  category->last = NULL;
1519 
1520  return 0;
1521 }
#define NULL
Definition: resample.c:96
struct ast_variable * root
Definition: main/config.c:240
void ast_variables_destroy(struct ast_variable *v)
Free variable list.
Definition: main/config.c:591
struct ast_variable * last
Definition: main/config.c:242

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

References ast_category_get().

Referenced by realtime_sorcery_store().

1063 {
1064  return !!ast_category_get(config, category_name, filter);
1065 }
struct ast_category * ast_category_get(const struct ast_config *config, const char *category_name, const char *filter)
Retrieve a category if it exists.
Definition: main/config.c:1022
static int filter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:709

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

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().

1158 {
1159  return (cat) ? cat->root : NULL;
1160 }
#define NULL
Definition: resample.c:96
struct ast_variable * root
Definition: main/config.c:240

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

References category_get_sep().

Referenced by add_message_id(), ast_category_exist(), ast_category_root(), 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().

1024 {
1025  return category_get_sep(config, category_name, filter, ',', 1);
1026 }
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)
Definition: main/config.c:1000
static int filter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:709

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

References ast_category::name.

Referenced by action_getconfig(), action_getconfigjson(), action_listcategories(), 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().

1029 {
1030  return category->name;
1031 }
char name[80]
Definition: main/config.c:226

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

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

Referenced by action_getconfig(), and action_getconfigjson().

1039 {
1040  struct ast_category_template_instance *template;
1041  struct ast_str *str;
1042  int first = 1;
1043 
1044  if (AST_LIST_EMPTY(&category->template_instances)) {
1045  return NULL;
1046  }
1047 
1048  str = ast_str_create(128);
1049  if (!str) {
1050  return NULL;
1051  }
1052 
1053  AST_LIST_TRAVERSE(&category->template_instances, template, next) {
1054  ast_str_append(&str, 0, "%s%s", first ? "" : ",", template->name);
1055  first = 0;
1056  }
1057 
1058  return str;
1059 }
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:1091
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:449
const char * str
Definition: app_jack.c:147
#define NULL
Definition: resample.c:96
struct ast_category::template_instance_list template_instances
struct ast_category_template_instance * next
Definition: main/config.c:222
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
struct sla_ringing_trunk * first
Definition: app_meetme.c:1092
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

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

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_comment::next, ast_variable::next, ast_category::root, var, and variable_clone().

Referenced by handle_updates(), and process_text_line().

1368 {
1369  struct ast_variable *var;
1371 
1372  x = ast_calloc(1, sizeof(*x));
1373  if (!x) {
1374  return -1;
1375  }
1376  strcpy(x->name, base->name);
1377  x->inst = base;
1378  AST_LIST_INSERT_TAIL(&new->template_instances, x, next);
1379  for (var = base->root; var; var = var->next) {
1380  struct ast_variable *cloned = variable_clone(var);
1381  if (!cloned) {
1382  return -1;
1383  }
1384  cloned->inherited = 1;
1385  ast_variable_append(new, cloned);
1386  }
1387  return 0;
1388 }
struct ast_variable * next
void ast_variable_append(struct ast_category *category, struct ast_variable *variable)
Definition: main/config.c:488
Structure for variables, used for configurations and for channel variables.
#define var
Definition: ast_expr2f.c:614
const struct ast_category * inst
Definition: main/config.c:221
struct ast_variable * root
Definition: main/config.c:240
struct ast_category_template_instance * next
Definition: main/config.c:222
static struct ast_variable * variable_clone(const struct ast_variable *old)
Definition: main/config.c:855
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:730
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
char name[80]
Definition: main/config.c:226

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

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

Referenced by AST_TEST_DEFINE(), and handle_updates().

1084 {
1085  struct ast_category *cur_category;
1086 
1087  if (!config || !config->root || !cat || !match) {
1088  return -1;
1089  }
1090 
1091  if (!strcasecmp(config->root->name, match)) {
1092  cat->next = config->root;
1093  cat->prev = NULL;
1094  config->root->prev = cat;
1095  config->root = cat;
1096  return 0;
1097  }
1098 
1099  for (cur_category = config->root->next; cur_category; cur_category = cur_category->next) {
1100  if (!strcasecmp(cur_category->name, match)) {
1101  cat->prev = cur_category->prev;
1102  cat->prev->next = cat;
1103 
1104  cat->next = cur_category;
1105  cur_category->prev = cat;
1106 
1107  return 0;
1108  }
1109  }
1110 
1111  return -1;
1112 }
struct ast_category * next
Definition: main/config.c:246
struct ast_category * prev
Definition: main/config.c:244
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:2315
#define NULL
Definition: resample.c:96
char name[80]
Definition: main/config.c:226
struct ast_category * root
Definition: main/config.c:251

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

References ast_category::ignored.

Referenced by action_getconfig(), and action_getconfigjson().

1034 {
1035  return category->ignored;
1036 }

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

References new_category().

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

2791 {
2792  struct ast_category *category;
2793 
2794  if ((category = ast_calloc(1, sizeof(*category))))
2795  ast_copy_string(category->name, name, sizeof(category->name));
2796  category->file = strdup(in_file);
2797  category->lineno = lineno; /* if you don't know the lineno, set it to 999999 or something real big */
2798  return category;
2799 }
char * file
The file name from whence this declaration was read.
Definition: main/config.c:233
void ast_copy_string(char *dst, const char *src, size_t size)
Definition: extconf.c:970
static const char name[]
Definition: cdr_mysql.c:74
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
char name[80]
Definition: main/config.c:226
#define strdup(a)
Definition: astmm.h:165

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

References new_category().

Referenced by AST_TEST_DEFINE(), and handle_updates().

996 {
997  return new_category(name, in_file, lineno, 1);
998 }
static struct ast_category * new_category(const char *name, const char *in_file, int lineno, int template)
Definition: main/config.c:971
static const char name[]
Definition: cdr_mysql.c:74

◆ ast_category_rename()

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

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

References ast_copy_string(), and ast_category::name.

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

1363 {
1364  ast_copy_string(cat->name, name, sizeof(cat->name));
1365 }
static const char name[]
Definition: cdr_mysql.c:74
char name[80]
Definition: main/config.c:226
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401

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

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

Referenced by config_function_read(), get_insecure_variable_from_config(), get_insecure_variable_from_sipregs(), realtime_sorcery(), realtime_sorcery_multi(), and register_realtime_peers_with_callbackextens().

1163 {
1164  struct ast_category *category = ast_category_get(config, cat, NULL);
1165 
1166  if (category)
1167  return category->root;
1168  return NULL;
1169 }
#define NULL
Definition: resample.c:96
struct ast_variable * root
Definition: main/config.c:240
struct ast_category * ast_category_get(const struct ast_config *config, const char *category_name, const char *filter)
Retrieve a category if it exists.
Definition: main/config.c:1022

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

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

Referenced by __queues_show(), _sip_show_peer(), _sip_show_peers(), ast_named_acl_find(), ast_queue_log(), close_mailbox(), copy_plain_file(), destroy_association(), find_realtime_gw(), handle_response_peerpoke(), handle_voicemail_show_users(), leave_voicemail(), load_module(), load_moh_classes(), load_realtime_rules(), local_ast_moh_start(), logger_queue_rt_start(), msg_create_from_file(), realtime_peer(), realtime_update_peer(), register_realtime_peers_with_callbackextens(), rename_file(), set_member_value(), sip_poke_noanswer(), sip_show_settings(), and vm_delete().

3364 {
3365  struct ast_config_engine *eng;
3366  if (!ast_realtime_enabled()) {
3367  return 0; /* There are no engines at all so fail early */
3368  }
3369 
3370  eng = find_engine(family, 1, NULL, 0, NULL, 0);
3371  if (eng)
3372  return 1;
3373  return 0;
3374 }
int ast_realtime_enabled(void)
Check if there&#39;s any realtime engines loaded.
Definition: main/config.c:3377
#define NULL
Definition: resample.c:96
Configuration engine structure, used to define realtime drivers.
static struct ast_config_engine * find_engine(const char *family, int priority, char *database, int dbsiz, char *table, int tabsiz)
Find realtime engine for realtime family.
Definition: main/config.c:3042

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

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

Referenced by AST_TEST_DEFINE(), and config_hook_exec().

3080 {
3081  struct ast_config *new_config = ast_config_new();
3082  struct ast_category *cat_iter;
3083 
3084  if (!new_config) {
3085  return NULL;
3086  }
3087 
3088  for (cat_iter = old->root; cat_iter; cat_iter = cat_iter->next) {
3089  struct ast_category *new_cat =
3090  ast_category_new(cat_iter->name, cat_iter->file, cat_iter->lineno);
3091  if (!new_cat) {
3092  goto fail;
3093  }
3094  ast_category_append(new_config, new_cat);
3095  if (cat_iter->root) {
3096  new_cat->root = ast_variables_dup(cat_iter->root);
3097  if (!new_cat->root) {
3098  goto fail;
3099  }
3100  new_cat->last = cat_iter->last;
3101  }
3102  }
3103 
3104  return new_config;
3105 
3106 fail:
3107  ast_config_destroy(new_config);
3108  return NULL;
3109 }
struct ast_category * next
Definition: main/config.c:246
char * file
The file name from whence this declaration was read.
Definition: main/config.c:233
void ast_category_append(struct ast_config *config, struct ast_category *category)
Appends a category to a config.
Definition: main/config.c:1067
#define NULL
Definition: resample.c:96
struct ast_variable * ast_variables_dup(struct ast_variable *var)
Duplicate variable list.
Definition: main/config.c:545
struct ast_variable * root
Definition: main/config.c:240
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
Definition: main/config.c:1523
struct ast_config * ast_config_new(void)
Create a new base configuration structure.
Definition: main/config.c:1390
char name[80]
Definition: main/config.c:226
struct ast_variable * last
Definition: main/config.c:242
struct ast_category * ast_category_new(const char *name, const char *in_file, int lineno)
Create a category.
Definition: main/config.c:990

◆ ast_config_destroy()

static void ast_config_destroy ( struct ast_config config)

Destroys a config.

Parameters
configpointer to config data structure

Free memory associated with a given config

Definition at line 1290 of file extconf.c.

References ast_category_destroy(), ast_free, ast_includes_destroy(), ast_config::includes, ast_category::next, 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_xmldoc_load_documentation(), build_cfg(), conf_exec(), config_function_read(), config_load(), config_module(), deinitialize_sorcery(), directory_exec(), do_reload(), festival_exec(), find_conf(), find_load_queue_rt_friendly(), find_realtime(), forward_message(), get_defaults(), get_insecure_variable_from_sippeers(), get_insecure_variable_from_sipregs(), handle_cli_dialplan_save(), hook_cb(), iax_provision_reload(), ineligible_configuration(), init_logger_chain(), initialize_cc_devstate_map(), initialize_cc_max_requests(), load_asterisk_conf(), load_config(), load_config_meetme(), load_indications(), load_module(), load_moh_classes(), load_odbc_config(), load_pktccops_config(), load_realtime_musiconhold(), load_realtime_rules(), load_values_config(), loader_config_init(), make_email_file(), mbl_load_config(), message_range_and_existence_check(), misdn_cfg_init(), my_load_module(), named_acl_find_realtime(), notify_new_message(), object_type_loaded_observer(), odbc_load_module(), osp_load(), parse_config(), pbx_load_config(), pbx_load_users(), play_message(), prep_email_sub_vars(), private_enum_init(), process_config(), read_password_from_file(), read_pjproject_startup_options(), realtime_directory(), realtime_multi_handler(), realtime_multi_mysql(), realtime_multi_pgsql(), realtime_sorcery_multi(), realtime_sqlite3_multi(), realtime_switch_common(), register_realtime_peers_with_callbackextens(), reload(), reload_config(), reload_followme(), reload_module(), reload_queue_rules(), reload_queues(), rtp_reload(), run_startup_commands(), set_config(), setup_dahdi_int(), show_users_realtime(), sla_load_config(), smdi_load(), sorcery_config_internal_load(), sorcery_realtime_retrieve_multiple(), tds_load_module(), unload_module(), update_realtime_members(), vm_change_password(), vm_forwardoptions(), vm_msg_forward(), vm_msg_play(), vm_msg_snapshot_create(), and write_password_to_file().

1291 {
1292  struct ast_category *cat, *catn;
1293 
1294  if (!cfg)
1295  return;
1296 
1297  ast_includes_destroy(cfg->includes);
1298 
1299  cat = cfg->root;
1300  while (cat) {
1302  catn = cat;
1303  cat = cat->next;
1304  free(catn);
1305  }
1306  free(cfg);
1307 }
struct ast_category * next
Definition: main/config.c:246
void free()
struct ast_variable * root
Definition: main/config.c:240
static void ast_variables_destroy(struct ast_variable *v)
Definition: extconf.c:1263
static void ast_includes_destroy(struct ast_config_include *incls)
Definition: extconf.c:1274

◆ ast_config_engine_deregister()

int ast_config_engine_deregister ( struct ast_config_engine del)

Deregister config engine.

Return values
0Always

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

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

Referenced by unload_module().

3007 {
3008  struct ast_config_engine *ptr, *last=NULL;
3009 
3011 
3012  for (ptr = config_engine_list; ptr; ptr=ptr->next) {
3013  if (ptr == del) {
3014  if (last)
3015  last->next = ptr->next;
3016  else
3017  config_engine_list = ptr->next;
3018  break;
3019  }
3020  last = ptr;
3021  }
3022 
3023  return 0;
3024 }
#define NULL
Definition: resample.c:96
Configuration engine structure, used to define realtime drivers.
struct ast_config_engine * next
#define SCOPED_MUTEX(varname, lock)
scoped lock specialization for mutexes
Definition: lock.h:587
struct sla_ringing_trunk * last
Definition: app_meetme.c:1092
ast_mutex_t lock
Definition: app_meetme.c:1091
static ast_mutex_t config_lock
Definition: main/config.c:214
static struct ast_config_engine * config_engine_list
Definition: main/config.c:215

◆ ast_config_engine_register()

int ast_config_engine_register ( struct ast_config_engine newconfig)

Register config engine.

Return values
1Always

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

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

Referenced by load_module().

2991 {
2992  struct ast_config_engine *ptr;
2993 
2995 
2996  if (!config_engine_list) {
2997  config_engine_list = new;
2998  } else {
2999  for (ptr = config_engine_list; ptr->next; ptr=ptr->next);
3000  ptr->next = new;
3001  }
3002 
3003  return 1;
3004 }
Configuration engine structure, used to define realtime drivers.
struct ast_config_engine * next
#define SCOPED_MUTEX(varname, lock)
scoped lock specialization for mutexes
Definition: lock.h:587
ast_mutex_t lock
Definition: app_meetme.c:1091
static ast_mutex_t config_lock
Definition: main/config.c:214
static struct ast_config_engine * config_engine_list
Definition: main/config.c:215

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

References ast_category_new(), ast_config::current, and ast_channel::name.

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

2784 {
2785  return cfg->current;
2786 }
struct ast_category * current
Definition: main/config.c:254

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

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

Referenced by AST_TEST_DEFINE().

4137 {
4138  struct cfg_hook *hook;
4139  if (!cfg_hooks) {
4141  hook_hash, NULL, hook_cmp);
4142  if (!cfg_hooks) {
4143  return -1;
4144  }
4145  }
4146 
4147  if (!(hook = ao2_alloc(sizeof(*hook), hook_destroy))) {
4148  return -1;
4149  }
4150 
4151  hook->hook_cb = hook_cb;
4152  hook->filename = ast_strdup(filename);
4153  hook->name = ast_strdup(name);
4154  hook->module = ast_strdup(module);
4155 
4156  ao2_link(cfg_hooks, hook);
4157  ao2_ref(hook, -1);
4158  return 0;
4159 }
static int hook_hash(const void *obj, const int flags)
Definition: main/config.c:4097
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
config_hook_cb hook_cb
Definition: main/config.c:4078
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static int hook_cmp(void *obj, void *arg, int flags)
Definition: main/config.c:4089
static struct ao2_container * cfg_hooks
Definition: main/config.c:77
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Definition: astobj2.h:1310
static void hook_destroy(void *obj)
Definition: main/config.c:4081
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
static const char name[]
Definition: cdr_mysql.c:74
const char * filename
Definition: main/config.c:4076
static int hook_cb(struct ast_config *cfg)
Definition: test_config.c:875
const char * module
Definition: main/config.c:4077
const char * name
Definition: main/config.c:4075
#define ao2_link(container, obj)
Definition: astobj2.h:1549

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

References ao2_find, ast_strdupa, cfg_hook::name, OBJ_NODATA, OBJ_POINTER, OBJ_UNLINK, and tmp().

Referenced by AST_TEST_DEFINE().

4105 {
4106  struct cfg_hook tmp;
4107 
4108  tmp.name = ast_strdupa(name);
4109 
4111 }
#define OBJ_POINTER
Definition: astobj2.h:1154
static int tmp()
Definition: bt_open.c:389
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
static struct ao2_container * cfg_hooks
Definition: main/config.c:77
static const char name[]
Definition: cdr_mysql.c:74
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756

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

References ast_log, ast_test_flag, 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 add_cfg_entry(), ast_config_load2(), config_curl(), config_ldap(), config_mysql(), config_odbc(), config_pgsql(), process_text_line(), reload_module(), and static_realtime_cb().

3113 {
3114  char db[256];
3115  char table[256];
3116  struct ast_config_engine *loader = &text_file_engine;
3117  struct ast_config *result;
3118 
3119  /* The config file itself bumps include_level by 1 */
3120  if (cfg->max_include_level > 0 && cfg->include_level == cfg->max_include_level + 1) {
3121  ast_log(LOG_WARNING, "Maximum Include level (%d) exceeded\n", cfg->max_include_level);
3122  return NULL;
3123  }
3124 
3125  cfg->include_level++;
3126 
3128  struct ast_config_engine *eng;
3129 
3130  eng = find_engine(filename, 1, db, sizeof(db), table, sizeof(table));
3131 
3132 
3133  if (eng && eng->load_func) {
3134  loader = eng;
3135  } else {
3136  eng = find_engine("global", 1, db, sizeof(db), table, sizeof(table));
3137  if (eng && eng->load_func)
3138  loader = eng;
3139  }
3140  }
3141 
3142  result = loader->load_func(db, table, filename, cfg, flags, suggested_include_file, who_asked);
3143 
3144  if (result && result != CONFIG_STATUS_FILEINVALID && result != CONFIG_STATUS_FILEUNCHANGED) {
3145  result->include_level--;
3146  config_hook_exec(filename, who_asked, result);
3147  } else if (result != CONFIG_STATUS_FILEINVALID) {
3148  cfg->include_level--;
3149  }
3150 
3151  return result;
3152 }
static struct ast_config_engine text_file_engine
Definition: main/config.c:3074
#define ast_test_flag(p, flag)
Definition: utils.h:63
static sqlite3 * db
#define LOG_WARNING
Definition: logger.h:274
#define CONFIG_STATUS_FILEINVALID
int include_level
Definition: main/config.c:256
#define NULL
Definition: resample.c:96
Configuration engine structure, used to define realtime drivers.
static char * table
Definition: cdr_odbc.c:58
#define ast_log
Definition: astobj2.c:42
#define CONFIG_STATUS_FILEUNCHANGED
static struct ast_config_engine * config_engine_list
Definition: main/config.c:215
static struct ast_config_engine * find_engine(const char *family, int priority, char *database, int dbsiz, char *table, int tabsiz)
Find realtime engine for realtime family.
Definition: main/config.c:3042
config_load_func * load_func
static void config_hook_exec(const char *filename, const char *module, const struct ast_config *cfg)
Definition: main/config.c:4113
static PGresult * result
Definition: cel_pgsql.c:88
int max_include_level
Definition: main/config.c:257

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

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_xmldoc_load_documentation(), do_reload(), iax_provision_reload(), init_logger_chain(), initialize_cc_devstate_map(), initialize_cc_max_requests(), load_asterisk_conf(), load_config(), load_indications(), loader_config_init(), misdn_cfg_init(), object_type_loaded_observer(), private_enum_init(), read_pjproject_startup_options(), rtp_reload(), run_startup_commands(), set_config(), and sorcery_config_internal_load().

3155 {
3156  struct ast_config *cfg;
3157  struct ast_config *result;
3158 
3159  cfg = ast_config_new();
3160  if (!cfg)
3161  return NULL;
3162 
3163  result = ast_config_internal_load(filename, cfg, flags, "", who_asked);
3164  if (!result || result == CONFIG_STATUS_FILEUNCHANGED || result == CONFIG_STATUS_FILEINVALID)
3165  ast_config_destroy(cfg);
3166 
3167  return result;
3168 }
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)
Definition: main/config.c:3112
#define CONFIG_STATUS_FILEINVALID
#define NULL
Definition: resample.c:96
#define CONFIG_STATUS_FILEUNCHANGED
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
Definition: main/config.c:1523
struct ast_config * ast_config_new(void)
Create a new base configuration structure.
Definition: main/config.c:1390
static PGresult * result
Definition: cel_pgsql.c:88

◆ ast_config_new()

static struct ast_config * ast_config_new ( void  )

Create a new base configuration structure.

Definition at line 3276 of file extconf.c.

References ast_calloc, config, MAX_INCLUDE_LEVEL, and ast_config::max_include_level.

Referenced by alloc_and_initialize_sorcery(), ast_config_copy(), ast_config_load2(), AST_TEST_DEFINE(), build_cfg(), find_load_queue_rt_friendly(), realtime_multi_curl(), realtime_multi_handler(), realtime_multi_ldap(), realtime_multi_mysql(), realtime_multi_odbc(), realtime_multi_pgsql(), realtime_sorcery_multi(), realtime_sqlite3_multi(), reload_module(), setup_dahdi_int(), and write_password_to_file().

3277 {
3278  struct ast_config *config;
3279 
3280  if ((config = ast_calloc(1, sizeof(*config))))
3282  return config;
3283 }
#define MAX_INCLUDE_LEVEL
Definition: extconf.c:895
char * config
Definition: conf2ael.c:66
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
int max_include_level
Definition: main/config.c:257

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

References ast_variable_retrieve(), and tmp().

Referenced by actual_load_config(), pbx_load_users(), process_config(), and search_directory_sub().

685 {
686  const char *tmp;
687  tmp = ast_variable_retrieve(cfg, cat, var);
688  if (!tmp) {
689  tmp = ast_variable_retrieve(cfg, "general", var);
690  }
691  return tmp;
692 }
static int tmp()
Definition: bt_open.c:389
#define var
Definition: ast_expr2f.c:614
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
Definition: main/config.c:694

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

References ast_config::current.

Referenced by ast_category_browse(), and process_text_line().

3365 {
3366  /* cast below is just to silence compiler warning about dropping "const" */
3367  cfg->current = (struct ast_category *) cat;
3368 }
struct ast_category * current
Definition: main/config.c:254

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

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

Referenced by named_acl_find_realtime(), and realtime_switch_common().

1173 {
1174  /*
1175  * The contents of this function are adapted from
1176  * an example of linked list merge sorting
1177  * copyright 2001 Simon Tatham.
1178  *
1179  * Permission is hereby granted, free of charge, to any person
1180  * obtaining a copy of this software and associated documentation
1181  * files (the "Software"), to deal in the Software without
1182  * restriction, including without limitation the rights to use,
1183  * copy, modify, merge, publish, distribute, sublicense, and/or
1184  * sell copies of the Software, and to permit persons to whom the
1185  * Software is furnished to do so, subject to the following
1186  * conditions:
1187  *
1188  * The above copyright notice and this permission notice shall be
1189  * included in all copies or substantial portions of the Software.
1190  *
1191  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1192  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
1193  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1194  * NONINFRINGEMENT. IN NO EVENT SHALL SIMON TATHAM BE LIABLE FOR
1195  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
1196  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1197  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1198  * SOFTWARE.
1199  */
1200 
1201  int insize = 1;
1202  struct ast_category *p, *q, *e, *tail;
1203  int nmerges, psize, qsize, i;
1204 
1205  /* If the descending flag was sent, we'll apply inversion to the comparison function's return. */
1206  if (descending) {
1207  descending = -1;
1208  } else {
1209  descending = 1;
1210  }
1211 
1212  if (!config->root) {
1213  return;
1214  }
1215 
1216  while (1) {
1217  p = config->root;
1218  config->root = NULL;
1219  tail = NULL;
1220 
1221  nmerges = 0; /* count number of merges we do in this pass */
1222 
1223  while (p) {
1224  nmerges++; /* there exists a merge to be done */
1225 
1226  /* step `insize' places along from p */
1227  q = p;
1228  psize = 0;
1229  for (i = 0; i < insize; i++) {
1230  psize++;
1231  q = q->next;
1232  if (!q) {
1233  break;
1234  }
1235  }
1236 
1237  /* if q hasn't fallen off end, we have two lists to merge */
1238  qsize = insize;
1239 
1240  /* now we have two lists; merge them */
1241  while (psize > 0 || (qsize > 0 && q)) {
1242  /* decide whether next element of merge comes from p or q */
1243  if (psize == 0) {
1244  /* p is empty; e must come from q. */
1245  e = q;
1246  q = q->next;
1247  qsize--;
1248  } else if (qsize == 0 || !q) {
1249  /* q is empty; e must come from p. */
1250  e = p; p = p->next; psize--;
1251  } else if ((comparator(p,q) * descending) <= 0) {
1252  /* First element of p is lower (or same) e must come from p. */
1253  e = p;
1254  p = p->next;
1255  psize--;
1256  } else {
1257  /* First element of q is lower; e must come from q. */
1258  e = q;
1259  q = q->next;
1260  qsize--;
1261  }
1262 
1263  /* add the next element to the merged list */
1264  if (tail) {
1265  tail->next = e;
1266  } else {
1267  config->root = e;
1268  }
1269  tail = e;
1270  }
1271 
1272  /* now p has stepped `insize' places along, and q has too */
1273  p = q;
1274  }
1275 
1276  tail->next = NULL;
1277 
1278  /* If we have done only one merge, we're finished. */
1279  if (nmerges <= 1) { /* allow for nmerges==0, the empty list case */
1280  return;
1281  }
1282 
1283  /* Otherwise repeat, merging lists twice the size */
1284  insize *= 2;
1285  }
1286 
1287 }
struct ast_category * next
Definition: main/config.c:246
#define NULL
Definition: resample.c:96
struct ast_category * root
Definition: main/config.c:251

◆ 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
Returns
0 on success or -1 on failure.

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

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().

2532 {
2534 }
static struct ast_generator generator
Definition: app_fax.c:359
int ast_config_text_file_save2(const char *configfile, const struct ast_config *cfg, const char *generator, uint32_t flags)
Save a config text file.
Definition: main/config.c:2555

◆ 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
Returns
0 on success or -1 on failure.

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

References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ao2_ref, ast_debug, ast_escape_semicolons(), AST_LIST_EMPTY, AST_LIST_LAST, AST_LIST_TRAVERSE, ast_log, ast_verb, ast_variable::blanklines, ast_comment::cmt, config_hook_exec(), CONFIG_SAVE_FLAG_PRESERVE_EFFECTIVE_CONTEXT, errno, ast_config_include::exec, ast_config_include::exec_file, ast_variable::file, 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::included_file, ast_config::includes, ast_variable::inherited, insert_leading_blank_lines(), ast_category_template_instance::inst, is_writable(), ast_variable::lineno, ast_category::lineno, LOG_ERROR, make_fn(), ast_variable::name, ast_category_template_instance::name, ast_category::name, ast_comment::next, ast_variable::next, ast_category::next, ast_config_include::next, NULL, ast_variable::object, ast_config_include::output, PATH_MAX, ast_variable::precomments, ast_category::precomments, ast_category::root, ast_config::root, ast_variable::sameline, ast_category::sameline, set_fn(), ast_category::template_instances, ast_variable::trailing, ast_category::trailing, ast_variable::value, and var.

Referenced by action_updateconfig(), and ast_config_text_file_save().

2556 {
2557  FILE *f;
2558  char fn[PATH_MAX];
2559  struct ast_variable *var;
2560  struct ast_category *cat;
2561  struct ast_comment *cmt;
2562  struct ast_config_include *incl;
2563  int blanklines = 0;
2564  struct ao2_container *fileset;
2565  struct inclfile *fi;
2566 
2569  if (!fileset) {
2570  /* Container creation failed. */
2571  return -1;
2572  }
2573 
2574  /* Check all the files for write access before attempting to modify any of them */
2575  for (incl = cfg->includes; incl; incl = incl->next) {
2576  /* reset all the output flags in case this isn't our first time saving this data */
2577  incl->output = 0;
2578 
2579  if (!incl->exec) {
2580  /* now make sure we have write access to the include file or its parent directory */
2581  make_fn(fn, sizeof(fn), incl->included_file, configfile);
2582  /* If the file itself doesn't exist, make sure we have write access to the directory */
2583  if (!is_writable(fn)) {
2584  return -1;
2585  }
2586  }
2587  }
2588 
2589  /* now make sure we have write access to the main config file or its parent directory */
2590  make_fn(fn, sizeof(fn), 0, configfile);
2591  if (!is_writable(fn)) {
2592  return -1;
2593  }
2594 
2595  /* Now that we know we have write access to all files, it's safe to start truncating them */
2596 
2597  /* go thru all the inclusions and make sure all the files involved (configfile plus all its inclusions)
2598  are all truncated to zero bytes and have that nice header*/
2599  for (incl = cfg->includes; incl; incl = incl->next) {
2600  if (!incl->exec) { /* leave the execs alone -- we'll write out the #exec directives, but won't zero out the include files or exec files*/
2601  /* normally, fn is just set to incl->included_file, prepended with config dir if relative */
2602  fi = set_fn(fn, sizeof(fn), incl->included_file, configfile, fileset);
2603  f = fopen(fn, "w");
2604  if (f) {
2605  gen_header(f, configfile, fn, generator);
2606  fclose(f); /* this should zero out the file */
2607  } else {
2608  ast_log(LOG_ERROR, "Unable to write %s (%s)\n", fn, strerror(errno));
2609  }
2610  if (fi) {
2611  ao2_ref(fi, -1);
2612  }
2613  }
2614  }
2615 
2616  /* just set fn to absolute ver of configfile */
2617  fi = set_fn(fn, sizeof(fn), 0, configfile, fileset);
2618  if (
2619 #ifdef __CYGWIN__
2620  (f = fopen(fn, "w+"))
2621 #else
2622  (f = fopen(fn, "w"))
2623 #endif
2624  ) {
2625  ast_verb(2, "Saving '%s'\n", fn);
2626  gen_header(f, configfile, fn, generator);
2627  cat = cfg->root;
2628  fclose(f);
2629  if (fi) {
2630  ao2_ref(fi, -1);
2631  }
2632 
2633  /* from here out, we open each involved file and concat the stuff we need to add to the end and immediately close... */
2634  /* since each var, cat, and associated comments can come from any file, we have to be
2635  mobile, and open each file, print, and close it on an entry-by-entry basis */
2636 
2637  while (cat) {
2638  fi = set_fn(fn, sizeof(fn), cat->file, configfile, fileset);
2639  f = fopen(fn, "a");
2640  if (!f) {
2641  ast_log(LOG_ERROR, "Unable to write %s (%s)\n", fn, strerror(errno));
2642  if (fi) {
2643  ao2_ref(fi, -1);
2644  }
2645  ao2_ref(fileset, -1);
2646  return -1;
2647  }
2648 
2649  /* dump any includes that happen before this category header */
2650  for (incl=cfg->includes; incl; incl = incl->next) {
2651  if (strcmp(incl->include_location_file, cat->file) == 0){
2652  if (cat->lineno > incl->include_location_lineno && !incl->output) {
2653  if (incl->exec)
2654  fprintf(f,"#exec \"%s\"\n", incl->exec_file);
2655  else
2656  fprintf(f,"#include \"%s\"\n", incl->included_file);
2657  incl->output = 1;
2658  }
2659  }
2660  }
2661 
2662  insert_leading_blank_lines(f, fi, cat->precomments, cat->lineno);
2663  /* Dump section with any appropriate comment */
2664  for (cmt = cat->precomments; cmt; cmt=cmt->next) {
2665  char *cmtp = cmt->cmt;
2666  while (cmtp && *cmtp == ';' && *(cmtp+1) == '!') {
2667  char *cmtp2 = strchr(cmtp+1, '\n');
2668  if (cmtp2)
2669  cmtp = cmtp2+1;
2670  else cmtp = 0;
2671  }
2672  if (cmtp)
2673  fprintf(f,"%s", cmtp);
2674  }
2675  fprintf(f, "[%s]", cat->name);
2676  if (cat->ignored || !AST_LIST_EMPTY(&cat->template_instances)) {
2677  fprintf(f, "(");
2678  if (cat->ignored) {
2679  fprintf(f, "!");
2680  }
2681  if (cat->ignored && !AST_LIST_EMPTY(&cat->template_instances)) {
2682  fprintf(f, ",");
2683  }
2684  if (!AST_LIST_EMPTY(&cat->template_instances)) {
2687  fprintf(f,"%s",x->name);
2688  if (x != AST_LIST_LAST(&cat->template_instances))
2689  fprintf(f,",");
2690  }
2691  }
2692  fprintf(f, ")");
2693  }
2694  for(cmt = cat->sameline; cmt; cmt=cmt->next)
2695  {
2696  fprintf(f,"%s", cmt->cmt);
2697  }
2698  if (!cat->sameline)
2699  fprintf(f,"\n");
2700  for (cmt = cat->trailing; cmt; cmt=cmt->next) {
2701  if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
2702  fprintf(f,"%s", cmt->cmt);
2703  }
2704  fclose(f);
2705  if (fi) {
2706  ao2_ref(fi, -1);
2707  }
2708 
2709  var = cat->root;
2710  while (var) {
2712  int found = 0;
2713 
2715  struct ast_variable *v;
2716  for (v = x->inst->root; v; v = v->next) {
2717 
2719  if (!strcasecmp(var->name, v->name) && !strcmp(var->value, v->value)) {
2720  found = 1;
2721  break;
2722  }
2723  } else {
2724  if (var->inherited) {
2725  found = 1;
2726  break;
2727  } else {
2728  if (!strcasecmp(var->name, v->name) && !strcmp(var->value, v->value)) {
2729  found = 1;
2730  break;
2731  }
2732  }
2733  }
2734  }
2735  if (found) {
2736  break;
2737  }
2738  }
2739  if (found) {
2740  var = var->next;
2741  continue;
2742  }
2743  fi = set_fn(fn, sizeof(fn), var->file, configfile, fileset);
2744  f = fopen(fn, "a");
2745  if (!f) {
2746  ast_debug(1, "Unable to open for writing: %s\n", fn);
2747  ast_verb(2, "Unable to write %s (%s)\n", fn, strerror(errno));
2748  if (fi) {
2749  ao2_ref(fi, -1);
2750  }
2751  ao2_ref(fileset, -1);
2752  return -1;
2753  }
2754 
2755  /* dump any includes that happen before this category header */
2756  for (incl=cfg->includes; incl; incl = incl->next) {
2757  if (strcmp(incl->include_location_file, var->file) == 0){
2758  if (var->lineno > incl->include_location_lineno && !incl->output) {
2759  if (incl->exec)
2760  fprintf(f,"#exec \"%s\"\n", incl->exec_file);
2761  else
2762  fprintf(f,"#include \"%s\"\n", incl->included_file);
2763  incl->output = 1;
2764  }
2765  }
2766  }
2767 
2768  insert_leading_blank_lines(f, fi, var->precomments, var->lineno);
2769  for (cmt = var->precomments; cmt; cmt=cmt->next) {
2770  if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
2771  fprintf(f,"%s", cmt->cmt);
2772  }
2773 
2774  { /* Block for 'escaped' scope */
2775  int escaped_len = 2 * strlen(var->value) + 1;
2776  char escaped[escaped_len];
2777 
2778  ast_escape_semicolons(var->value, escaped, escaped_len);
2779 
2780  if (var->sameline) {
2781  fprintf(f, "%s %s %s %s", var->name, (var->object ? "=>" : "="),
2782  escaped, var->sameline->cmt);
2783  } else {
2784  fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="),
2785  escaped);
2786  }
2787  }
2788 
2789  for (cmt = var->trailing; cmt; cmt=cmt->next) {
2790  if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
2791  fprintf(f,"%s", cmt->cmt);
2792  }
2793  if (var->blanklines) {
2794  blanklines = var->blanklines;
2795  while (blanklines--)
2796  fprintf(f, "\n");
2797  }
2798 
2799  fclose(f);
2800  if (fi) {
2801  ao2_ref(fi, -1);
2802  }
2803 
2804  var = var->next;
2805  }
2806  cat = cat->next;
2807  }
2808  ast_verb(2, "Saving '%s': saved\n", fn);
2809  } else {
2810  ast_debug(1, "Unable to open for writing: %s\n", fn);
2811  ast_verb(2, "Unable to write '%s' (%s)\n", fn, strerror(errno));
2812  if (fi) {
2813  ao2_ref(fi, -1);
2814  }
2815  ao2_ref(fileset, -1);
2816  return -1;
2817  }
2818 
2819  /* Now, for files with trailing #include/#exec statements,
2820  we have to make sure every entry is output */
2821  for (incl=cfg->includes; incl; incl = incl->next) {
2822  if (!incl->output) {
2823  /* open the respective file */
2824  fi = set_fn(fn, sizeof(fn), incl->include_location_file, configfile, fileset);
2825  f = fopen(fn, "a");
2826  if (!f) {
2827  ast_debug(1, "Unable to open for writing: %s\n", fn);
2828  ast_verb(2, "Unable to write %s (%s)\n", fn, strerror(errno));
2829  if (fi) {
2830  ao2_ref(fi, -1);
2831  }
2832  ao2_ref(fileset, -1);
2833  return -1;
2834  }
2835 
2836  /* output the respective include */
2837  if (incl->exec)
2838  fprintf(f,"#exec \"%s\"\n", incl->exec_file);
2839  else
2840  fprintf(f,"#include \"%s\"\n", incl->included_file);
2841  fclose(f);
2842  incl->output = 1;
2843  if (fi) {
2844  ao2_ref(fi, -1);
2845  }
2846  }
2847  }
2848  ao2_ref(fileset, -1); /* this should destroy the hash container */
2849 
2850  /* pass new configuration to any config hooks */
2851  config_hook_exec(configfile, generator, cfg);
2852 
2853  return 0;
2854 }
struct ast_variable * next
struct ast_category * next
Definition: main/config.c:246
struct ast_comment * sameline
Definition: main/config.c:237
Structure to keep comments for rewriting configuration files.
Definition: main/config.c:84
char * file
The file name from whence this declaration was read.
Definition: main/config.c:233
struct ast_comment * next
Definition: main/config.c:85
char * include_location_file
file name in which the include occurs
Definition: main/config.c:266
struct ast_config_include * includes
Definition: main/config.c:258
char cmt[0]
Definition: main/config.c:87
Structure for variables, used for configurations and for channel variables.
struct ast_comment * sameline
#define var
Definition: ast_expr2f.c:614
const struct ast_category * inst
Definition: main/config.c:221
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:449
char * ast_escape_semicolons(const char *string, char *outbuf, int buflen)
Escape semicolons found in a string.
Definition: main/utils.c:665
#define NULL
Definition: resample.c:96
char * exec_file
if it&#39;s an exec, you&#39;ll have both the /var/tmp to read, and the original script
Definition: main/config.c:273
static void gen_header(FILE *f1, const char *configfile, const char *fn, const char *generator)
Definition: main/config.c:2399
#define ast_verb(level,...)
Definition: logger.h:463
static void make_fn(char *fn, size_t fn_size, const char *file, const char *configfile)
Definition: main/config.c:2425
struct ast_comment * trailing
static int is_writable(const char *fn)
Definition: main/config.c:2536
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
struct ast_category::template_instance_list template_instances
struct ast_comment * trailing
Definition: main/config.c:238
char * included_file
file name included
Definition: main/config.c:278
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ast_variable * root
Definition: main/config.c:240
struct ast_comment * precomments
Definition: main/config.c:236
struct ast_category_template_instance * next
Definition: main/config.c:222
#define LOG_ERROR
Definition: logger.h:285
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Definition: astobj2.h:1310
static struct ast_generator generator
Definition: app_fax.c:359
static struct inclfile * set_fn(char *fn, size_t fn_size, const char *file, const char *configfile, struct ao2_container *fileset)
Definition: main/config.c:2440
int errno
struct ast_comment * precomments
#define AST_LIST_LAST(head)
Returns the last entry contained in a list.
Definition: linkedlists.h:428
static int hash_string(const void *obj, const int flags)
Definition: main/config.c:173
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
char name[80]
Definition: main/config.c:226
struct ast_config_include * next
Definition: main/config.c:282
static void config_hook_exec(const char *filename, const char *module, const struct ast_config *cfg)
Definition: main/config.c:4113
#define PATH_MAX
Definition: asterisk.h:40
Generic container type.
static int hashtab_compare_strings(void *a, void *b, int flags)
Definition: main/config.c:193
struct ast_category * root
Definition: main/config.c:251
static void insert_leading_blank_lines(FILE *fp, struct inclfile *fi, struct ast_comment *precomments, int lineno)
Definition: main/config.c:2495

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

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().

3607 {
3608  RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
3609  int res = 0;
3610  va_list ap;
3611 
3612  va_start(ap, lookup);
3613  if (realtime_arguments_to_fields(ap, &fields)) {
3614  res = -1;
3615  }
3616  va_end(ap);
3617 
3618  if (res) {
3619  return -1;
3620  }
3621 
3622  return ast_destroy_realtime_fields(family, keyfield, lookup, fields);
3623 }
int ast_destroy_realtime_fields(const char *family, const char *keyfield, const char *lookup, const struct ast_variable *fields)
Destroy realtime configuration.
Definition: main/config.c:3586
Structure for variables, used for configurations and for channel variables.
#define NULL
Definition: resample.c:96
#define realtime_arguments_to_fields(ap, result)
Definition: main/config.c:3170
#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:911
void ast_variables_destroy(struct ast_variable *v)
Free variable list.
Definition: main/config.c:591

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

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

Referenced by ast_destroy_realtime(), and sorcery_realtime_delete().

3587 {
3588  struct ast_config_engine *eng;
3589  int res = -1, i;
3590  char db[256];
3591  char table[256];
3592 
3593  for (i = 1; ; i++) {
3594  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3595  if (eng->destroy_func && ((res = eng->destroy_func(db, table, keyfield, lookup, fields)) >= 0)) {
3596  break;
3597  }
3598  } else {
3599  break;
3600  }
3601  }
3602 
3603  return res;
3604 }
realtime_destroy * destroy_func
static sqlite3 * db
Configuration engine structure, used to define realtime drivers.
static char * table
Definition: cdr_odbc.c:58
static struct ast_config_engine * find_engine(const char *family, int priority, char *database, int dbsiz, char *table, int tabsiz)
Find realtime engine for realtime family.
Definition: main/config.c:3042

◆ ast_include_find()

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

Definition at line 1164 of file extconf.c.

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

Referenced by ast_include_new().

1165 {
1166  struct ast_config_include *x;
1167  for (x=conf->includes;x;x=x->next)
1168  {
1169  if (strcmp(x->included_file,included_file) == 0)
1170  return x;
1171  }
1172  return 0;
1173 }
struct ast_config_include * includes
Definition: main/config.c:258
char * included_file
file name included
Definition: main/config.c:278
struct ast_config_include * next
Definition: main/config.c:282

◆ ast_include_new()

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

Definition at line 1075 of file extconf.c.

References ast_calloc, ast_include_find(), ast_includes_destroy(), ast_log, ast_strdup, ast_strlen_zero, ast_config::includes, LOG_WARNING, and NULL.

Referenced by AST_TEST_DEFINE(), and process_text_line().

1076 {
1077  /* a file should be included ONCE. Otherwise, if one of the instances is changed,
1078  then all be changed. -- how do we know to include it? -- Handling modified
1079  instances is possible, I'd have
1080  to create a new master for each instance. */
1081  struct ast_config_include *inc;
1082 
1083  inc = ast_include_find(conf, included_file);
1084  if (inc)
1085  {
1086  inc->inclusion_count++;
1087  snprintf(real_included_file_name, real_included_file_name_size, "%s~~%d", included_file, inc->inclusion_count);
1088  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);
1089  } else
1090  *real_included_file_name = 0;
1091 
1092  inc = ast_calloc(1,sizeof(struct ast_config_include));
1093  inc->include_location_file = ast_strdup(from_file);
1094  inc->include_location_lineno = from_lineno;
1095  if (!ast_strlen_zero(real_included_file_name))
1096  inc->included_file = ast_strdup(real_included_file_name);
1097  else
1099 
1100  inc->exec = is_exec;
1101  if (is_exec)
1102  inc->exec_file = ast_strdup(exec_file);
1103 
1104  /* attach this new struct to the conf struct */
1105  inc->next = conf->includes;
1106  conf->includes = inc;
1107 
1108  return inc;
1109 }
char * include_location_file
file name in which the include occurs
Definition: main/config.c:266
struct ast_config_include * includes
Definition: main/config.c:258
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
char * exec_file
if it&#39;s an exec, you&#39;ll have both the /var/tmp to read, and the original script
Definition: main/config.c:273
char * included_file
file name included
Definition: main/config.c:278
static force_inline int ast_strlen_zero(const char *s)
Definition: extconf.c:952
static void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Definition: extconf.c:2195
#define LOG_WARNING
Definition: extconf.c:139
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
struct ast_config_include * next
Definition: main/config.c:282
static struct ast_config_include * ast_include_find(struct ast_config *conf, const char *included_file)
Definition: extconf.c:1164

◆ ast_include_rename()

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

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

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_config::includes, ast_category::last, name, ast_variable::name, ast_variable::next, ast_category::next, ast_config_include::next, ast_category::root, ast_config::root, str, and ast_variable::value.

Referenced by action_updateconfig().

386 {
387  struct ast_config_include *incl;
388  struct ast_category *cat;
389  char *str;
390 
391  int from_len = strlen(from_file);
392  int to_len = strlen(to_file);
393 
394  if (strcmp(from_file, to_file) == 0) /* no use wasting time if the name is the same */
395  return;
396 
397  /* the manager code allows you to read in one config file, then
398  * write it back out under a different name. But, the new arrangement
399  * ties output lines to the file name. So, before you try to write
400  * the config file to disk, better riffle thru the data and make sure
401  * the file names are changed.
402  */
403  /* file names are on categories, includes (of course), and on variables. So,
404  * traverse all this and swap names */
405 
406  for (incl = conf->includes; incl; incl=incl->next) {
407  if (strcmp(incl->include_location_file,from_file) == 0) {
408  if (from_len >= to_len)
409  strcpy(incl->include_location_file, to_file);
410  else {
411  /* Keep the old filename if the allocation fails. */
412  str = ast_strdup(to_file);
413  if (str) {
415  incl->include_location_file = str;
416  }
417  }
418  }
419  }
420  for (cat = conf->root; cat; cat = cat->next) {
421  struct ast_variable **prev;
422  struct ast_variable *v;
423  struct ast_variable *new_var;
424 
425  if (strcmp(cat->file,from_file) == 0) {
426  if (from_len >= to_len)
427  strcpy(cat->file, to_file);
428  else {
429  /* Keep the old filename if the allocation fails. */
430  str = ast_strdup(to_file);
431  if (str) {
432  ast_free(cat->file);
433  cat->file = str;
434  }
435  }
436  }
437  for (prev = &cat->root, v = cat->root; v; prev = &v->next, v = v->next) {
438  if (strcmp(v->file, from_file)) {
439  continue;
440  }
441 
442  /*
443  * Calculate actual space available. The file string is
444  * intentionally stuffed before the name string just so we can
445  * do this.
446  */
447  if (to_len < v->name - v->file) {
448  /* The new name will fit in the available space. */
449  str = (char *) v->file;/* Stupid compiler complains about discarding qualifiers even though I used a cast. */
450  strcpy(str, to_file);/* SAFE */
451  continue;
452  }
453 
454  /* Keep the old filename if the allocation fails. */
455  new_var = ast_variable_new(v->name, v->value, to_file);
456  if (!new_var) {
457  continue;
458  }
459 
460  /* Move items from the old list node to the replacement node. */
461  ast_variable_move(new_var, v);
462 
463  /* Replace the old node in the list with the new node. */
464  new_var->next = v->next;
465  if (cat->last == v) {
466  cat->last = new_var;
467  }
468  *prev = new_var;
469 
471 
472  v = new_var;
473  }
474  }
475 }
struct ast_variable * next
struct ast_category * next
Definition: main/config.c:246
static void ast_variable_destroy(struct ast_variable *doomed)
Definition: main/config.c:537
char * file
The file name from whence this declaration was read.
Definition: main/config.c:233
char * include_location_file
file name in which the include occurs
Definition: main/config.c:266
struct ast_config_include * includes
Definition: main/config.c:258
Structure for variables, used for configurations and for channel variables.
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
const char * str
Definition: app_jack.c:147
#define ast_variable_new(name, value, filename)
struct ast_variable * root
Definition: main/config.c:240
static const char name[]
Definition: cdr_mysql.c:74
#define ast_free(a)
Definition: astmm.h:182
struct ast_variable * last
Definition: main/config.c:242
struct ast_config_include * next
Definition: main/config.c:282
struct ast_category * root
Definition: main/config.c:251
static void ast_variable_move(struct ast_variable *dst_var, struct ast_variable *src_var)
Definition: main/config.c:324

◆ ast_load_realtime()

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

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

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_realtime_gw(), find_user_realtime(), leave_queue(), load_realtime_musiconhold(), queue_function_queuegetchannel(), queue_function_queuewaitingcount(), realtime_peer(), realtime_peer_by_addr(), realtime_peer_by_name(), realtime_peer_get_sippeer_helper(), realtime_switch_common(), realtime_user(), rt_extend_conf(), and vm_allocate_dh().

3340 {
3341  RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
3342  int field_res = 0;
3343  va_list ap;
3344 
3345  va_start(ap, family);
3346  if (realtime_arguments_to_fields(ap, &fields)) {
3347  field_res = -1;
3348  }
3349  va_end(ap);
3350 
3351  if (field_res) {
3352  return NULL;
3353  }
3354 
3355  if (!fields) {
3356  return NULL;
3357  }
3358 
3359  return ast_load_realtime_fields(family, fields);
3360 }
Structure for variables, used for configurations and for channel variables.
#define NULL
Definition: resample.c:96
#define realtime_arguments_to_fields(ap, result)
Definition: main/config.c:3170
#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:911
struct ast_variable * ast_load_realtime_fields(const char *family, const struct ast_variable *fields)
Retrieve realtime configuration.
Definition: main/config.c:3304
void ast_variables_destroy(struct ast_variable *v)
Free variable list.
Definition: main/config.c:591

◆ ast_load_realtime_all()

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

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

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().

3288 {
3289  RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
3290  struct ast_variable *res = NULL;
3291  va_list ap;
3292 
3293  va_start(ap, family);
3294  realtime_arguments_to_fields(ap, &fields);
3295  va_end(ap);
3296 
3297  if (fields) {
3298  res = ast_load_realtime_all_fields(family, fields);
3299  }
3300 
3301  return res;
3302 }
Structure for variables, used for configurations and for channel variables.
struct ast_variable * ast_load_realtime_all_fields(const char *family, const struct ast_variable *fields)
Definition: main/config.c:3266
#define NULL
Definition: resample.c:96
#define realtime_arguments_to_fields(ap, result)
Definition: main/config.c:3170
#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:911
void ast_variables_destroy(struct ast_variable *v)
Free variable list.
Definition: main/config.c:591

◆ ast_load_realtime_all_fields()

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

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

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

Referenced by ast_load_realtime_all(), and ast_load_realtime_fields().

3267 {
3268  struct ast_config_engine *eng;
3269  char db[256];
3270  char table[256];
3271  struct ast_variable *res=NULL;
3272  int i;
3273 
3274  for (i = 1; ; i++) {
3275  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3276  if (eng->realtime_func && (res = eng->realtime_func(db, table, fields))) {
3277  return res;
3278  }
3279  } else {
3280  return NULL;
3281  }
3282  }
3283 
3284  return res;
3285 }
static sqlite3 * db
Structure for variables, used for configurations and for channel variables.
#define NULL
Definition: resample.c:96
realtime_var_get * realtime_func
Configuration engine structure, used to define realtime drivers.
static char * table
Definition: cdr_odbc.c:58
static struct ast_config_engine * find_engine(const char *family, int priority, char *database, int dbsiz, char *table, int tabsiz)
Find realtime engine for realtime family.
Definition: main/config.c:3042

◆ 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

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

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

Referenced by ast_load_realtime(), and sorcery_realtime_retrieve_fields().

3305 {
3306  struct ast_variable *res;
3307  struct ast_variable *cur;
3308  struct ast_variable **prev;
3309 
3310  res = ast_load_realtime_all_fields(family, fields);
3311 
3312  /* Filter the list. */
3313  prev = &res;
3314  cur = res;
3315  while (cur) {
3316  if (ast_strlen_zero(cur->value)) {
3317  /* Eliminate empty entries */
3318  struct ast_variable *next;
3319 
3320  next = cur->next;
3321  *prev = next;
3322  ast_variable_destroy(cur);
3323  cur = next;
3324  } else {
3325  /* Make blank entries empty and keep them. */
3326  if (cur->value[0] == ' ' && cur->value[1] == '\0') {
3327  char *vptr = (char *) cur->value;
3328 
3329  vptr[0] = '\0';
3330  }
3331 
3332  prev = &cur->next;
3333  cur = cur->next;
3334  }
3335  }
3336  return res;
3337 }
struct ast_variable * next
static void ast_variable_destroy(struct ast_variable *doomed)
Definition: main/config.c:537
Structure for variables, used for configurations and for channel variables.
struct ast_variable * ast_load_realtime_all_fields(const char *family, const struct ast_variable *fields)
Definition: main/config.c:3266
#define ast_strlen_zero(foo)
Definition: strings.h:52

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

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(), get_insecure_variable_from_sippeers(), get_insecure_variable_from_sipregs(), load_module(), load_realtime_musiconhold(), load_realtime_rules(), named_acl_find_realtime(), realtime_directory(), realtime_switch_common(), register_realtime_peers_with_callbackextens(), set_member_value(), show_users_realtime(), and update_realtime_members().

3453 {
3454  RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
3455  va_list ap;
3456 
3457  va_start(ap, family);
3458  realtime_arguments_to_fields(ap, &fields);
3459  va_end(ap);
3460 
3461  if (!fields) {
3462  return NULL;
3463  }
3464 
3465  return ast_load_realtime_multientry_fields(family, fields);
3466 }
Structure for variables, used for configurations and for channel variables.
#define NULL
Definition: resample.c:96
#define realtime_arguments_to_fields(ap, result)
Definition: main/config.c:3170
#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:911
void ast_variables_destroy(struct ast_variable *v)
Free variable list.
Definition: main/config.c:591
struct ast_config * ast_load_realtime_multientry_fields(const char *family, const struct ast_variable *fields)
Retrieve realtime configuration.
Definition: main/config.c:3426

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

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().

3427 {
3428  struct ast_config_engine *eng;
3429  char db[256];
3430  char table[256];
3431  struct ast_config *res = NULL;
3432  int i;
3433 
3434  for (i = 1; ; i++) {
3435  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3436  if (eng->realtime_multi_func && (res = eng->realtime_multi_func(db, table, fields))) {
3437  /* If we were returned an empty cfg, destroy it and return NULL */
3438  if (!res->root) {
3439  ast_config_destroy(res);
3440  res = NULL;
3441  }
3442  break;
3443  }
3444  } else {
3445  break;
3446  }
3447  }
3448 
3449  return res;
3450 }
static sqlite3 * db
realtime_multi_get * realtime_multi_func
#define NULL
Definition: resample.c:96
Configuration engine structure, used to define realtime drivers.
static char * table
Definition: cdr_odbc.c:58
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
Definition: main/config.c:1523
static struct ast_config_engine * find_engine(const char *family, int priority, char *database, int dbsiz, char *table, int tabsiz)
Find realtime engine for realtime family.
Definition: main/config.c:3042
struct ast_category * root
Definition: main/config.c:251

◆ 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.
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.

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

References ahp, ast_app_parse_timelen(), ast_debug, ast_gethostbyname(), ast_inet_ntoa(), ast_skip_blanks(), ast_sockaddr_parse(), ast_sockaddr_stringify(), ast_strdupa, ast_strlen_zero, buf, errno, error(), hp, 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_user(), configure_local_rtp(), double_handler_fn(), general_set(), iax2_call(), iax2_request(), int_handler_fn(), load_asterisk_conf(), load_config(), load_values_config(), new_realtime_sqlite3_db(), realtime_peer(), reload_config(), rtp_reload(), set_config(), setup_rtp_connection(), setup_rtp_remote(), setup_udptl_connection(), sockaddr_handler_fn(), timelen_handler_fn(), uint_handler_fn(), and xfer_set().

3659 {
3660  va_list ap;
3661  int error = 0;
3662 
3663  va_start(ap, p_result);
3664  switch (flags & PARSE_TYPE) {
3665  case PARSE_INT32:
3666  {
3667  long int x = 0;
3668  int32_t *result = p_result;
3669  int32_t def = result ? *result : 0, high = INT32_MAX, low = INT32_MIN;
3670  char *endptr = NULL;
3671 
3672  /* optional arguments: default value and/or (low, high) */
3673  if (flags & PARSE_DEFAULT) {
3674  def = va_arg(ap, int32_t);
3675  }
3676  if (flags & (PARSE_IN_RANGE | PARSE_OUT_RANGE)) {
3677  low = va_arg(ap, int32_t);
3678  high = va_arg(ap, int32_t);
3679  }
3680  if (ast_strlen_zero(arg)) {
3681  error = 1;
3682  goto int32_done;
3683  }
3684  errno = 0;
3685  x = strtol(arg, &endptr, 0);
3686  if (*endptr || errno || x < INT32_MIN || x > INT32_MAX) {
3687  /* Parse error, or type out of int32_t bounds */
3688  error = 1;
3689  goto int32_done;
3690  }
3691  error = (x < low) || (x > high);
3692  if (flags & PARSE_RANGE_DEFAULTS) {
3693  if (x < low) {
3694  def = low;
3695  } else if (x > high) {
3696  def = high;
3697  }
3698  }
3699  if (flags & PARSE_OUT_RANGE) {
3700  error = !error;
3701  }
3702 int32_done:
3703  if (result) {
3704  *result = error ? def : x;
3705  }
3706 
3707  ast_debug(3, "extract int from [%s] in [%d, %d] gives [%ld](%d)\n",
3708  arg, low, high, result ? *result : x, error);
3709  break;
3710  }
3711 
3712  case PARSE_UINT32:
3713  {
3714  unsigned long int x = 0;
3715  uint32_t *result = p_result;
3716  uint32_t def = result ? *result : 0, low = 0, high = UINT32_MAX;
3717  char *endptr = NULL;
3718 
3719  /* optional argument: first default value, then range */
3720  if (flags & PARSE_DEFAULT) {
3721  def = va_arg(ap, uint32_t);
3722  }
3723  if (flags & (PARSE_IN_RANGE|PARSE_OUT_RANGE)) {
3724  /* range requested, update bounds */
3725  low = va_arg(ap, uint32_t);
3726  high = va_arg(ap, uint32_t);
3727  }
3728 
3729  if (ast_strlen_zero(arg)) {
3730  error = 1;
3731  goto uint32_done;
3732  }
3733  /* strtoul will happilly and silently negate negative numbers */
3734  arg = ast_skip_blanks(arg);
3735  if (*arg == '-') {
3736  error = 1;
3737  goto uint32_done;
3738  }
3739  errno = 0;
3740  x = strtoul(arg, &endptr, 0);
3741  if (*endptr || errno || x > UINT32_MAX) {
3742  error = 1;
3743  goto uint32_done;
3744  }
3745  error = (x < low) || (x > high);
3746  if (flags & PARSE_RANGE_DEFAULTS) {
3747  if (x < low) {
3748  def = low;
3749  } else if (x > high) {
3750  def = high;
3751  }
3752  }
3753  if (flags & PARSE_OUT_RANGE) {
3754  error = !error;
3755  }
3756 uint32_done:
3757  if (result) {
3758  *result = error ? def : x;
3759  }
3760  ast_debug(3, "extract uint from [%s] in [%u, %u] gives [%lu](%d)\n",
3761  arg, low, high, result ? *result : x, error);
3762  break;
3763  }
3764 
3765  case PARSE_TIMELEN:
3766  {
3767  int x = 0;
3768  int *result = p_result;
3769  int def = result ? *result : 0;
3770  int high = INT_MAX;
3771  int low = INT_MIN;
3772  enum ast_timelen defunit;
3773 
3774  defunit = va_arg(ap, enum ast_timelen);
3775  /* optional arguments: default value and/or (low, high) */
3776  if (flags & PARSE_DEFAULT) {
3777  def = va_arg(ap, int);
3778  }
3779  if (flags & (PARSE_IN_RANGE | PARSE_OUT_RANGE)) {
3780  low = va_arg(ap, int);
3781  high = va_arg(ap, int);
3782  }
3783  if (ast_strlen_zero(arg)) {
3784  error = 1;
3785  goto timelen_done;
3786  }
3787  error = ast_app_parse_timelen(arg, &x, defunit);
3788  if (error || x < INT_MIN || x > INT_MAX) {
3789  /* Parse error, or type out of int bounds */
3790  error = 1;
3791  goto timelen_done;
3792  }
3793  error = (x < low) || (x > high);
3794  if (flags & PARSE_RANGE_DEFAULTS) {
3795  if (x < low) {
3796  def = low;
3797  } else if (x > high) {
3798  def = high;
3799  }
3800  }
3801  if (flags & PARSE_OUT_RANGE) {
3802  error = !error;
3803  }
3804 timelen_done:
3805  if (result) {
3806  *result = error ? def : x;
3807  }
3808 
3809  ast_debug(3, "extract timelen from [%s] in [%d, %d] gives [%d](%d)\n",
3810  arg, low, high, result ? *result : x, error);
3811  break;
3812  }
3813 
3814  case PARSE_DOUBLE:
3815  {
3816  double *result = p_result;
3817  double x = 0, def = result ? *result : 0, low = -HUGE_VAL, high = HUGE_VAL;
3818  char *endptr = NULL;
3819 
3820  /* optional argument: first default value, then range */
3821  if (flags & PARSE_DEFAULT) {
3822  def = va_arg(ap, double);
3823  }
3824  if (flags & (PARSE_IN_RANGE | PARSE_OUT_RANGE)) {
3825  /* range requested, update bounds */
3826  low = va_arg(ap, double);
3827  high = va_arg(ap, double);
3828  }
3829  if (ast_strlen_zero(arg)) {
3830  error = 1;
3831  goto double_done;
3832  }
3833  errno = 0;
3834  x = strtod(arg, &endptr);
3835  if (*endptr || errno == ERANGE) {
3836  error = 1;
3837  goto double_done;
3838  }
3839  error = (x < low) || (x > high);
3840  if (flags & PARSE_OUT_RANGE) {
3841  error = !error;
3842  }
3843 double_done:
3844  if (result) {
3845  *result = error ? def : x;
3846  }
3847  ast_debug(3, "extract double from [%s] in [%f, %f] gives [%f](%d)\n",
3848  arg, low, high, result ? *result : x, error);
3849  break;
3850  }
3851  case PARSE_ADDR:
3852  {
3853  struct ast_sockaddr *addr = (struct ast_sockaddr *)p_result;
3854 
3855  if (!ast_sockaddr_parse(addr, arg, flags & PARSE_PORT_MASK)) {
3856  error = 1;
3857  }
3858 
3859  ast_debug(3, "extract addr from %s gives %s(%d)\n",
3860  arg, ast_sockaddr_stringify(addr), error);
3861 
3862  break;
3863  }
3864  case PARSE_INADDR: /* TODO Remove this (use PARSE_ADDR instead). */
3865  {
3866  char *port, *buf;
3867  struct sockaddr_in _sa_buf; /* buffer for the result */
3868  struct sockaddr_in *sa = p_result ?
3869  (struct sockaddr_in *)p_result : &_sa_buf;
3870  /* default is either the supplied value or the result itself */
3871  struct sockaddr_in *def = (flags & PARSE_DEFAULT) ?
3872  va_arg(ap, struct sockaddr_in *) : sa;
3873  struct hostent *hp;
3874  struct ast_hostent ahp;
3875 
3876  memset(&_sa_buf, '\0', sizeof(_sa_buf)); /* clear buffer */
3877  /* duplicate the string to strip away the :port */
3878  port = ast_strdupa(arg);
3879  buf = strsep(&port, ":");
3880  sa->sin_family = AF_INET; /* assign family */
3881  /*
3882  * honor the ports flag setting, assign default value
3883  * in case of errors or field unset.
3884  */
3885  flags &= PARSE_PORT_MASK; /* the only flags left to process */
3886  if (port) {
3887  if (flags == PARSE_PORT_FORBID) {
3888  error = 1; /* port was forbidden */
3889  sa->sin_port = def->sin_port;
3890  } else if (flags == PARSE_PORT_IGNORE)
3891  sa->sin_port = def->sin_port;
3892  else /* accept or require */
3893  sa->sin_port = htons(strtol(port, NULL, 0));
3894  } else {
3895  sa->sin_port = def->sin_port;
3896  if (flags == PARSE_PORT_REQUIRE)
3897  error = 1;
3898  }
3899  /* Now deal with host part, even if we have errors before. */
3900  hp = ast_gethostbyname(buf, &ahp);
3901  if (hp) /* resolved successfully */
3902  memcpy(&sa->sin_addr, hp->h_addr, sizeof(sa->sin_addr));
3903  else {
3904  error = 1;
3905  sa->sin_addr = def->sin_addr;
3906  }
3907  ast_debug(3,
3908  "extract inaddr from [%s] gives [%s:%d](%d)\n",
3909  arg, ast_inet_ntoa(sa->sin_addr),
3910  ntohs(sa->sin_port), error);
3911  break;
3912  }
3913  }
3914  va_end(ap);
3915  return error;
3916 }
int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
Parse an IPv4 or IPv6 address string.
Definition: netsock2.c:230
#define UINT32_MAX
Definition: ast_expr2f.c:87
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define NULL
Definition: resample.c:96
#define INT32_MAX
Definition: ast_expr2f.c:78
Socket address structure.
Definition: netsock2.h:97
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define INT32_MIN
Definition: ast_expr2f.c:69
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
static struct ast_hostent ahp
Definition: chan_skinny.c:1235
int errno
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition: netsock2.h:260
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
Definition: strings.h:157
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
Definition: main/utils.c:782
struct hostent * ast_gethostbyname(const char *host, struct ast_hostent *hp)
Thread-safe gethostbyname function to use in Asterisk.
Definition: main/utils.c:197
char * strsep(char **str, const char *delims)
static PGresult * result
Definition: cel_pgsql.c:88
int error(const char *format,...)
Definition: utils/frame.c:999
int int32_t
Definition: db.h:60
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:3113
static struct hostent * hp
Definition: chan_skinny.c:1236

◆ ast_realtime_append_mapping()

int ast_realtime_append_mapping ( const char *  name,
const char *  driver,
const char *  database,
const char *  table,
int  priority 
)

Add an explicit mapping for a family.

Parameters
nameFamily name
driverDriver to use
databaseDatabase to access
tableTable to use
priorityPriority of this mapping

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

References ast_calloc, ast_verb, config_maps, ast_config_map::database, ast_config_map::driver, map, ast_config_map::name, ast_config_map::next, priority, ast_config_map::priority, ast_config_map::stuff, and ast_config_map::table.

Referenced by load_module(), and reload_module().

2872 {
2873  struct ast_config_map *map;
2874  char *dst;
2875  int length;
2876 
2877  length = sizeof(*map);
2878  length += strlen(name) + 1;
2879  length += strlen(driver) + 1;
2880  length += strlen(database) + 1;
2881  if (table)
2882  length += strlen(table) + 1;
2883 
2884  if (!(map = ast_calloc(1, length)))
2885  return -1;
2886 
2887  dst = map->stuff; /* writable space starts here */
2888  map->name = strcpy(dst, name);
2889  dst += strlen(dst) + 1;
2890  map->driver = strcpy(dst, driver);
2891  dst += strlen(dst) + 1;
2892  map->database = strcpy(dst, database);
2893  if (table) {
2894  dst += strlen(dst) + 1;
2895  map->table = strcpy(dst, table);
2896  }
2897  map->priority = priority;
2898  map->next = config_maps;
2899  config_maps = map;
2900 
2901  ast_verb(2, "Binding %s to %s/%s/%s\n", map->name, map->driver, map->database, map->table ? map->table : map->name);
2902 
2903  return 0;
2904 }
struct ast_config_map * next
Definition: main/config.c:200
static int * map
Definition: misdn_config.c:438
const char * database
Definition: main/config.c:207
static struct ast_config_map * config_maps
const char * table
Definition: main/config.c:209
static int priority
#define ast_verb(level,...)
Definition: logger.h:463
static char * table
Definition: cdr_odbc.c:58
const char * name
Definition: main/config.c:203
static const char name[]
Definition: cdr_mysql.c:74
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
const char * driver
Definition: main/config.c:205

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

Referenced by realtime_multi_pgsql(), and realtime_pgsql().

3626 {
3627  char *orig = chunk;
3628  for (; *chunk; chunk++) {
3629  if (*chunk == '^' && strchr("0123456789ABCDEFabcdef", chunk[1]) && strchr("0123456789ABCDEFabcdef", chunk[2])) {
3630  sscanf(chunk + 1, "%02hhX", (unsigned char *)chunk);
3631  memmove(chunk + 1, chunk + 3, strlen(chunk + 3) + 1);
3632  }
3633  }
3634  return orig;
3635 }

◆ ast_realtime_enabled()

int ast_realtime_enabled ( void  )

Check if there's any realtime engines loaded.

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

References config_maps.

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

3378 {
3379  return config_maps ? 1 : 0;
3380 }
static struct ast_config_map * config_maps

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

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

3638 {
3639  if (!strchr(chunk, ';') && !strchr(chunk, '^')) {
3640  ast_str_set(dest, maxlen, "%s", chunk);
3641  } else {
3642  ast_str_reset(*dest);
3643  for (; *chunk; chunk++) {
3644  if (strchr(";^", *chunk)) {
3645  ast_str_append(dest, maxlen, "^%02hhX", *chunk);
3646  } else {
3647  ast_str_append(dest, maxlen, "%c", *chunk);
3648  }
3649  }
3650  }
3651  return ast_str_buffer(*dest);
3652 }
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
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:1091
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:1065
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:653

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

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

Referenced by ast_named_acl_find(), and sorcery_realtime_open().

3027 {
3028  struct ast_config_map *map;
3030 
3031  for (map = config_maps; map; map = map->next) {
3032  if (!strcasecmp(family, map->name)) {
3033  return 1;
3034  }
3035  }
3036  ast_debug(5, "Failed to find a realtime mapping for %s\n", family);
3037 
3038  return 0;
3039 }
struct ast_config_map * next
Definition: main/config.c:200
static int * map
Definition: misdn_config.c:438
static struct ast_config_map * config_maps
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define SCOPED_MUTEX(varname, lock)
scoped lock specialization for mutexes
Definition: lock.h:587
ast_mutex_t lock
Definition: app_meetme.c:1091
static ast_mutex_t config_lock
Definition: main/config.c:214
const char * name
Definition: main/config.c:203

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

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

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

3383 {
3384  struct ast_config_engine *eng;
3385  char db[256];
3386  char table[256];
3387  va_list ap;
3388  int res = -1, i;
3389 
3390  va_start(ap, family);
3391  for (i = 1; ; i++) {
3392  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3393  /* If the require succeeds, it returns 0. */
3394  if (eng->require_func && !(res = eng->require_func(db, table, ap))) {
3395  break;
3396  }
3397  } else {
3398  break;
3399  }
3400  }
3401  va_end(ap);
3402 
3403  return res;
3404 }
static sqlite3 * db
Configuration engine structure, used to define realtime drivers.
static char * table
Definition: cdr_odbc.c:58
realtime_require * require_func
static struct ast_config_engine * find_engine(const char *family, int priority, char *database, int dbsiz, char *table, int tabsiz)
Find realtime engine for realtime family.
Definition: main/config.c:3042

◆ ast_rq_is_int()

int ast_rq_is_int ( require_type  type)
inline

Check if require type is an integer type.

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

Referenced by realtime_require_handler(), 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 3570 of file main/config.c.

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().

3571 {
3572  RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
3573  va_list ap;
3574 
3575  va_start(ap, family);
3576  realtime_arguments_to_fields(ap, &fields);
3577  va_end(ap);
3578 
3579  if (!fields) {
3580  return -1;
3581  }
3582 
3583  return ast_store_realtime_fields(family, fields);
3584 }
Structure for variables, used for configurations and for channel variables.
#define NULL
Definition: resample.c:96
#define realtime_arguments_to_fields(ap, result)
Definition: main/config.c:3170
#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:911
void ast_variables_destroy(struct ast_variable *v)
Free variable list.
Definition: main/config.c:591
int ast_store_realtime_fields(const char *family, const struct ast_variable *fields)
Create realtime configuration.
Definition: main/config.c:3549

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

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

Referenced by ast_store_realtime(), and sorcery_realtime_create().

3550 {
3551  struct ast_config_engine *eng;
3552  int res = -1, i;
3553  char db[256];
3554  char table[256];
3555 
3556  for (i = 1; ; i++) {
3557  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3558  /* If the store succeeds, it returns >= 0*/
3559  if (eng->store_func && ((res = eng->store_func(db, table, fields)) >= 0)) {
3560  break;
3561  }
3562  } else {
3563  break;
3564  }
3565  }
3566 
3567  return res;
3568 }
static sqlite3 * db
realtime_store * store_func
Configuration engine structure, used to define realtime drivers.
static char * table
Definition: cdr_odbc.c:58
static struct ast_config_engine * find_engine(const char *family, int priority, char *database, int dbsiz, char *table, int tabsiz)
Find realtime engine for realtime family.
Definition: main/config.c:3042

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

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

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

3407 {
3408  struct ast_config_engine *eng;
3409  char db[256];
3410  char table[256];
3411  int res = -1, i;
3412 
3413  for (i = 1; ; i++) {
3414  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3415  if (eng->unload_func) {
3416  /* Do this for ALL engines */
3417  res = eng->unload_func(db, table);
3418  }
3419  } else {
3420  break;
3421  }
3422  }
3423  return res;
3424 }
static sqlite3 * db
realtime_unload * unload_func
Configuration engine structure, used to define realtime drivers.
static char * table
Definition: cdr_odbc.c:58
static struct ast_config_engine * find_engine(const char *family, int priority, char *database, int dbsiz, char *table, int tabsiz)
Find realtime engine for realtime family.
Definition: main/config.c:3042

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

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().

3526 {
3527  RAII_VAR(struct ast_variable *, lookup_fields, NULL, ast_variables_destroy);
3528  RAII_VAR(struct ast_variable *, update_fields, NULL, ast_variables_destroy);
3529  va_list ap;
3530 
3531  va_start(ap, family);
3532  /* XXX: If we wanted to pass no lookup fields (select all), we'd be
3533  * out of luck. realtime_arguments_to_fields expects at least one key
3534  * value pair. */
3535  realtime_arguments_to_fields(ap, &lookup_fields);
3536  va_end(ap);
3537 
3538  va_start(ap, family);
3539  realtime_arguments_to_fields2(ap, 1, &update_fields);
3540  va_end(ap);
3541 
3542  if (!lookup_fields || !update_fields) {
3543  return -1;
3544  }
3545 
3546  return ast_update2_realtime_fields(family, lookup_fields, update_fields);
3547 }
int ast_update2_realtime_fields(const char *family, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields)
Update realtime configuration.
Definition: main/config.c:3505
Structure for variables, used for configurations and for channel variables.
#define NULL
Definition: resample.c:96
#define realtime_arguments_to_fields(ap, result)
Definition: main/config.c:3170
static int realtime_arguments_to_fields2(va_list ap, int skip, struct ast_variable **result)
Definition: main/config.c:3185
#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:911
void ast_variables_destroy(struct ast_variable *v)
Free variable list.
Definition: main/config.c:591

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

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

Referenced by ast_update2_realtime().

3506 {
3507  struct ast_config_engine *eng;
3508  int res = -1, i;
3509  char db[256];
3510  char table[256];
3511 
3512  for (i = 1; ; i++) {
3513  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3514  if (eng->update2_func && !(res = eng->update2_func(db, table, lookup_fields, update_fields))) {
3515  break;
3516  }
3517  } else {
3518  break;
3519  }
3520  }
3521 
3522  return res;
3523 }
static sqlite3 * db
Configuration engine structure, used to define realtime drivers.
static char * table
Definition: cdr_odbc.c:58
realtime_update2 * update2_func
static struct ast_config_engine * find_engine(const char *family, int priority, char *database, int dbsiz, char *table, int tabsiz)
Find realtime engine for realtime family.
Definition: main/config.c:3042

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

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

Referenced by cli_realtime_update(), conf_run(), destroy_association(), function_realtime_write(), handle_response_peerpoke(), leave_voicemail(), realtime_update_peer(), rename_file(), rt_extend_conf(), sip_poke_noanswer(), and update_realtime_member_field().

3490 {
3491  RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
3492  va_list ap;
3493 
3494  va_start(ap, lookup);
3495  realtime_arguments_to_fields(ap, &fields);
3496  va_end(ap);
3497 
3498  if (!fields) {
3499  return -1;
3500  }
3501 
3502  return ast_update_realtime_fields(family, keyfield, lookup, fields);
3503 }
Structure for variables, used for configurations and for channel variables.
int ast_update_realtime_fields(const char *family, const char *keyfield, const char *lookup, const struct ast_variable *fields)
Update realtime configuration.
Definition: main/config.c:3468
#define NULL
Definition: resample.c:96
#define realtime_arguments_to_fields(ap, result)
Definition: main/config.c:3170
#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:911
void ast_variables_destroy(struct ast_variable *v)
Free variable list.
Definition: main/config.c:591

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

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

Referenced by ast_update_realtime(), and sorcery_realtime_update().

3469 {
3470  struct ast_config_engine *eng;
3471  int res = -1, i;
3472  char db[256];
3473  char table[256];
3474 
3475  for (i = 1; ; i++) {
3476  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3477  /* If the update succeeds, it returns >= 0. */
3478  if (eng->update_func && ((res = eng->update_func(db, table, keyfield, lookup, fields)) >= 0)) {
3479  break;
3480  }
3481  } else {
3482  break;
3483  }
3484  }
3485 
3486  return res;
3487 }
static sqlite3 * db
realtime_update * update_func
Configuration engine structure, used to define realtime drivers.
static char * table
Definition: cdr_odbc.c:58
static struct ast_config_engine * find_engine(const char *family, int priority, char *database, int dbsiz, char *table, int tabsiz)
Find realtime engine for realtime family.
Definition: main/config.c:3042

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

References ast_category_get(), ast_config::last_browse, ast_category::name, 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(), actual_load_config(), adsi_load(), ast_cli_perms_init(), AST_TEST_DEFINE(), ast_variable_retrieve(), ast_xmldoc_load_documentation(), build_calendar(), build_device(), caldav_load_calendar(), conf_exec(), config_load(), 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_config(), load_general_config(), load_module(), load_moh_classes(), load_odbc_config(), load_pktccops_config(), load_users(), load_values_config(), load_zonemessages(), loader_config_init(), mbl_load_adapter(), mbl_load_config(), mbl_load_device(), misdn_cfg_init(), my_connect_db(), my_load_module(), new_realtime_sqlite3_db(), odbc_load_module(), osp_create_provider(), parse_config(), parse_tone_zone(), pbx_load_config(), process_my_load_module(), read_pjproject_startup_options(), realtime_directory(), reload(), reload_config(), reload_followme(), reload_module(), reload_queue_rules(), reload_single_queue(), rtp_reload(), run_startup_commands(), search_directory_sub(), set_config(), setup_dahdi_int(), show_users_realtime(), sip_cli_notify(), sla_build_station(), sla_build_trunk(), smdi_load(), store_config(), tds_load_module(), and test_config_validity().

1217 {
1218  struct ast_category *cat = NULL;
1219 
1220  if (category && config->last_browse && (config->last_browse->name == category))
1221  cat = config->last_browse;
1222  else
1223  cat = ast_category_get(config, category);
1224 
1225  return (cat) ? cat->root : NULL;
1226 }
#define NULL
Definition: resample.c:96
static struct ast_category * ast_category_get(const struct ast_config *config, const char *category_name)
Definition: extconf.c:1211
struct ast_variable * root
Definition: main/config.c:240
struct ast_category * last_browse
Definition: main/config.c:255
char name[80]
Definition: main/config.c:226

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

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

Referenced by handle_updates().

1400 {
1401  struct ast_variable *cur, *prev=NULL, *curn;
1402  int res = -1;
1403  int num_item = 0;
1404  int req_item;
1405 
1406  req_item = -1;
1407  if (!ast_strlen_zero(line)) {
1408  /* Requesting to delete by item number. */
1409  if (sscanf(line, "%30d", &req_item) != 1
1410  || req_item < 0) {
1411  /* Invalid item number to delete. */
1412  return -1;
1413  }
1414  }
1415 
1416  prev = NULL;
1417  cur = category->root;
1418  while (cur) {
1419  curn = cur->next;
1420  /* Delete by item number or by variable name with optional value. */
1421  if ((0 <= req_item && num_item == req_item)
1422  || (req_item < 0 && !strcasecmp(cur->name, variable)
1423  && (ast_strlen_zero(match) || !strcasecmp(cur->value, match)))) {
1424  if (prev) {
1425  prev->next = cur->next;
1426  if (cur == category->last)
1427  category->last = prev;
1428  } else {
1429  category->root = cur->next;
1430  if (cur == category->last)
1431  category->last = NULL;
1432  }
1433  ast_variable_destroy(cur);
1434  res = 0;
1435  } else
1436  prev = cur;
1437 
1438  cur = curn;
1439  ++num_item;
1440  }
1441  return res;
1442 }
struct ast_variable * next
static void ast_variable_destroy(struct ast_variable *doomed)
Definition: main/config.c:537
Structure for variables, used for configurations and for channel variables.
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:2315
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct ast_variable * root
Definition: main/config.c:240
struct ast_variable * last
Definition: main/config.c:242

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

References ast_variable_find_in_list(), and ast_category::root.

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

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

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

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

Referenced by ast_ari_callback(), ast_sorcery_changeset_create(), AST_TEST_DEFINE(), ast_variable_find(), handle_export_primitives(), and load_realtime_musiconhold().

831 {
832  const struct ast_variable *v;
833 
834  for (v = list; v; v = v->next) {
835  if (!strcasecmp(variable, v->name)) {
836  return v->value;
837  }
838  }
839  return NULL;
840 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
#define NULL
Definition: resample.c:96

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

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().

843 {
844  const struct ast_variable *v;
845  const char *found = NULL;
846 
847  for (v = list; v; v = v->next) {
848  if (!strcasecmp(variable, v->name)) {
849  found = v->value;
850  }
851  }
852  return found;
853 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
#define NULL
Definition: resample.c:96

◆ 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
variablename 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 740 of file main/config.c.

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

Referenced by ast_variable_lists_match(), and realtime_sorcery_store().

741 {
742  const struct ast_variable *v;
743 
744  for (v = list; v; v = v->next) {
745  if (!strcasecmp(variable_name, v->name)) {
746  return v;
747  }
748  }
749  return NULL;
750 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
#define NULL
Definition: resample.c:96

◆ ast_variable_insert()

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

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

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

Referenced by AST_TEST_DEFINE(), and handle_updates().

502 {
503  struct ast_variable *cur = category->root;
504  int lineno;
505  int insertline;
506 
507  if (!variable || sscanf(line, "%30d", &insertline) != 1) {
508  return;
509  }
510  if (!insertline) {
511  variable->next = category->root;
512  category->root = variable;
513  } else {
514  for (lineno = 1; lineno < insertline; lineno++) {
515  cur = cur->next;
516  if (!cur->next) {
517  break;
518  }
519  }
520  variable->next = cur->next;
521  cur->next = variable;
522  }
523 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
struct ast_variable * root
Definition: main/config.c:240

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

References ast_assert, ast_variable::next, and NULL.

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

649 {
650  struct ast_variable *curr;
651  ast_assert(head != NULL);
652 
653  if (!*head) {
654  *head = newvar;
655  } else {
656  if (search_hint == NULL) {
657  search_hint = *head;
658  }
659  for (curr = search_hint; curr->next; curr = curr->next);
660  curr->next = newvar;
661  }
662 
663  for (curr = newvar; curr->next; curr = curr->next);
664 
665  return curr;
666 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96

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

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

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

669 {
670  struct ast_variable *v, **prev = head;
671 
672  for (v = *head; v; prev = &v->next, v = v->next) {
673  if (!strcmp(v->name, replacement->name)) {
674  replacement->next = v->next;
675  *prev = replacement;
676  ast_free(v);
677  return 0;
678  }
679  }
680 
681  return -1;
682 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
#define ast_free(a)
Definition: astmm.h:182

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

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

Referenced by ast_sip_cli_print_sorcery_objectset(), and stir_shaken_cli_show().

623 {
624  struct ast_variable *p, *q;
625  struct ast_variable top;
626  int changed = 1;
627  memset(&top, 0, sizeof(top));
628  top.next = start;
629  if (start != NULL && start->next != NULL) {
630  while (changed) {
631  changed = 0;
632  q = &top;
633  p = top.next;
634  while (p->next != NULL) {
635  if (p->next != NULL && strcmp(p->name, p->next->name) > 0) {
636  q->next = variable_list_switch(p, p->next);
637  changed = 1;
638  }
639  q = p;
640  if (p->next != NULL)
641  p = p->next;
642  }
643  }
644  }
645  return top.next;
646 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
#define NULL
Definition: resample.c:96
static struct ast_variable * variable_list_switch(struct ast_variable *l1, struct ast_variable *l2)
Definition: main/config.c:615

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

References ast_free, ast_strdup, ast_variable_find_variable_in_list(), ast_variables_match(), if(), 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().

773 {
774  const struct ast_variable *field;
775  int right_count = 0;
776  int left_count = 0;
777 
778  if (left == right) {
779  return 1;
780  }
781 
782  if (!(left && right)) {
783  return 0;
784  }
785 
786  for (field = right; field; field = field->next) {
787  char *space = strrchr(field->name, ' ');
788  const struct ast_variable *old;
789  char * name = (char *)field->name;
790 
791  if (space) {
792  name = ast_strdup(field->name);
793  if (!name) {
794  return 0;
795  }
796  name[space - field->name] = '\0';
797  }
798 
799  old = ast_variable_find_variable_in_list(left, name);
800  if (name != field->name) {
801  ast_free(name);
802  }
803 
804  if (exact_match) {
805  if (!old || strcmp(old->value, field->value)) {
806  return 0;
807  }
808  } else {
809  if (!ast_variables_match(old, field)) {
810  return 0;
811  }
812  }
813 
814  right_count++;
815  }
816 
817  if (exact_match) {
818  for (field = left; field; field = field->next) {
819  left_count++;
820  }
821 
822  if (right_count != left_count) {
823  return 0;
824  }
825  }
826 
827  return 1;
828 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
if(!yyg->yy_init)
Definition: ast_expr2f.c:868
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
int ast_variables_match(const struct ast_variable *left, const struct ast_variable *right)
Tests 2 variable values to see if they match.
Definition: main/config.c:752
static const char name[]
Definition: cdr_mysql.c:74
#define ast_free(a)
Definition: astmm.h:182
const struct ast_variable * ast_variable_find_variable_in_list(const struct ast_variable *list, const char *variable_name)
Gets a variable from a variable list by name.
Definition: main/config.c:740

◆ ast_variable_retrieve()

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

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

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

Referenced by __init_manager(), __queues_show(), actual_load_config(), advanced_options(), ast_config_option(), ast_init_logger_for_socket_console(), AST_TEST_DEFINE(), conf_exec(), config_module(), directory_exec(), festival_exec(), find_realtime(), forward_message(), get_defaults(), get_insecure_variable_from_config(), get_insecure_variable_from_sipregs(), iax_template_parse(), ineligible_configuration(), init_acf_query(), init_logger_chain(), initialize_cc_devstate_map_helper(), initialize_cc_max_requests(), internal_aco_type_find(), load_config(), load_config_meetme(), load_indications(), load_module(), load_mysql_config(), load_realtime_musiconhold(), load_realtime_rules(), load_tech_calendars(), load_values_config(), loader_config_init(), make_email_file(), mbl_load_adapter(), mbl_load_device(), message_range_and_existence_check(), my_load_config_number(), my_load_config_string(), named_acl_find_realtime(), notify_new_message(), odbc_load_module(), osp_load(), parse_config(), pbx_load_config(), pbx_load_users(), 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(), search_directory_sub(), set_config(), set_member_value(), setup_dahdi_int(), sla_build_station(), sla_build_trunk(), sla_load_config(), tds_load_module(), vm_allocate_dh(), vm_change_password(), vm_forwardoptions(), vm_msg_forward(), vm_msg_play(), and vm_msg_snapshot_create().

695 {
696  struct ast_variable *v;
697 
698  if (category) {
699  for (v = ast_variable_browse(config, category); v; v = v->next) {
700  if (!strcasecmp(variable, v->name)) {
701  return v->value;
702  }
703  }
704  } else {
705  struct ast_category *cat;
706 
707  for (cat = config->root; cat; cat = cat->next) {
708  for (v = cat->root; v; v = v->next) {
709  if (!strcasecmp(variable, v->name)) {
710  return v->value;
711  }
712  }
713  }
714  }
715 
716  return NULL;
717 }
struct ast_variable * next
struct ast_category * next
Definition: main/config.c:246
Structure for variables, used for configurations and for channel variables.
#define NULL
Definition: resample.c:96
struct ast_variable * root
Definition: main/config.c:240
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Definition: main/config.c:602
struct ast_category * root
Definition: main/config.c:251

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

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

721 {
722  struct ast_category *cat = NULL;
723  const char *value;
724 
725  while ((cat = ast_category_browse_filtered(config, category, cat, filter))) {
726  value = ast_variable_find(cat, variable);
727  if (value) {
728  return value;
729  }
730  }
731 
732  return NULL;
733 }
#define NULL
Definition: resample.c:96
int value
Definition: syslog.c:37
const char * ast_variable_find(const struct ast_category *category, const char *variable)
Gets a variable value from a specific category structure by name.
Definition: main/config.c:735
static int filter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:709
struct ast_category * ast_category_browse_filtered(struct ast_config *config, const char *category_name, struct ast_category *prev, const char *filter)
Browse categories with filters.
Definition: main/config.c:1335

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

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

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

1446 {
1447  struct ast_variable *cur, *prev=NULL, *newer=NULL;
1448 
1449  for (cur = category->root; cur; prev = cur, cur = cur->next) {
1450  if (strcasecmp(cur->name, variable) ||
1451  (!ast_strlen_zero(match) && strcasecmp(cur->value, match)))
1452  continue;
1453 
1454  if (!(newer = ast_variable_new(variable, value, cur->file)))
1455  return -1;
1456 
1457  ast_variable_move(newer, cur);
1458  newer->object = newer->object || object;
1459 
1460  /* Replace the old node in the list with the new node. */
1461  newer->next = cur->next;
1462  if (prev)
1463  prev->next = newer;
1464  else
1465  category->root = newer;
1466  if (category->last == cur)
1467  category->last = newer;
1468 
1469  ast_variable_destroy(cur);
1470 
1471  return 0;
1472  }
1473 
1474  /* Could not find variable to update */
1475  return -1;
1476 }
struct ast_variable * next
static void ast_variable_destroy(struct ast_variable *doomed)
Definition: main/config.c:537
Structure for variables, used for configurations and for channel variables.
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:2315
#define NULL
Definition: resample.c:96
int value
Definition: syslog.c:37
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_variable_new(name, value, filename)
struct ast_variable * root
Definition: main/config.c:240
struct ast_variable * last
Definition: main/config.c:242
static void ast_variable_move(struct ast_variable *dst_var, struct ast_variable *src_var)
Definition: main/config.c:324

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

References ast_variable_destroy(), and ast_variable::next.

Referenced by __init_manager(), aco_set_defaults(), action_messagesend(), action_originate(), add_message_id(), announce_to_dial(), ast_ari_asterisk_update_object(), ast_ari_callback(), ast_ari_channels_originate(), ast_ari_channels_originate_with_id(), 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_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_update2_realtime(), ast_update_realtime(), ast_var_channel_types(), ast_var_channel_types_table(), ast_variables_dup(), auth_http_callback(), build_gateway(), build_peer(), calendar_destructor(), can_reuse_registration(), check_expiration_thread(), check_peer_ok(), cli_contact_get_container(), cli_realtime_load(), conf_run(), copy_plain_file(), create_mwi_subscriptions(), destroy_dahdi_pvt(), destroy_endpoint(), destroy_fast_originate_helper(), dup_vars(), endpoint_destructor(), external_media_audiosocket_tcp(), external_media_rtp_udp(), fields_handler(), find_conf_realtime(), find_load_queue_rt_friendly(), find_realtime(), find_realtime_gw(), find_user_realtime(), free_entry(), free_outgoing(), free_user(), function_realtime_read(), function_realtime_readdestroy(), generic_http_callback(), get_insecure_variable_from_sipregs(), 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(), ldap_loadentry(), leave_queue(), load_realtime_musiconhold(), local_ast_moh_start(), manager_free_user(), manager_notify_channel(), manager_notify_endpoint(), manager_notify_uri(), manager_sipnotify(), mkintf(), notify_ami_channel_data_destroy(), notify_ami_data_destroy(), notify_ami_uri_data_destroy(), object_type_loaded_observer(), originate_exec(), 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_handler(), realtime_ldap_base(), realtime_ldap_base_ap(), realtime_ldap_result_to_vars(), realtime_matchmore(), realtime_odbc(), realtime_peer(), realtime_peer_by_addr(), realtime_peer_by_name(), realtime_peer_get_sippeer_helper(), realtime_user(), realtimefield_read(), registration_deleted_observer(), return_sorcery_object(), row_to_varlist(), rt_extend_conf(), session_destructor(), sip_aor_to_ami(), sip_destroy_peer(), sip_pvt_dtor(), 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(), stir_shaken_cli_show(), table_configs_free(), test_sorcery_object_destroy(), test_sorcery_transform(), transport_apply(), update_ldap(), user_destructor(), and vm_allocate_dh().

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

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

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

Referenced by action_originate(), ast_ari_callback(), ast_config_copy(), authenticate(), get_insecure_variable_from_sippeers(), get_insecure_variable_from_sipregs(), 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().

546 {
547  struct ast_variable *cloned;
548  struct ast_variable *tmp;
549 
550  if (!(cloned = ast_variable_new(var->name, var->value, var->file))) {
551  return NULL;
552  }
553 
554  tmp = cloned;
555 
556  while ((var = var->next)) {
557  if (!(tmp->next = ast_variable_new(var->name, var->value, var->file))) {
558  ast_variables_destroy(cloned);
559  return NULL;
560  }
561  tmp = tmp->next;
562  }
563 
564  return cloned;
565 }
struct ast_variable * next
static int tmp()
Definition: bt_open.c:389
Structure for variables, used for configurations and for channel variables.
#define NULL
Definition: resample.c:96
#define ast_variable_new(name, value, filename)
void ast_variables_destroy(struct ast_variable *v)
Free variable list.
Definition: main/config.c:591

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

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

Referenced by ast_variable_lists_match().

753 {
754  char *op;
755 
756  if (left == right) {
757  return 1;
758  }
759 
760  if (!(left && right)) {
761  return 0;
762  }
763 
764  op = strrchr(right->name, ' ');
765  if (op) {
766  op++;
767  }
768 
769  return ast_strings_match(left->value, op ? ast_strdupa(op) : NULL, right->value);
770 }
#define NULL
Definition: resample.c:96
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
int ast_strings_match(const char *left, const char *op, const char *right)
Compares 2 strings using realtime-style operators.
Definition: strings.c:248

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

References ast_comment::next, ast_variable::next, NULL, and var.

Referenced by astman_get_variables_order().

568 {
569  struct ast_variable *var1, *var2;
570 
571  var1 = var;
572 
573  if (!var1 || !var1->next) {
574  return var1;
575  }
576 
577  var2 = var1->next;
578  var1->next = NULL;
579 
580  while (var2) {
581  struct ast_variable *next = var2->next;
582 
583  var2->next = var1;
584  var1 = var2;
585  var2 = next;
586  }
587 
588  return var1;
589 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
#define var
Definition: ast_expr2f.c:614
#define NULL
Definition: resample.c:96

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

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

Referenced by asterisk_daemon().

4067 {
4069  /* This is separate from the module load so cleanup can happen very late. */
4071  return 0;
4072 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
static void config_shutdown(void)
Definition: main/config.c:4048
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
static struct ast_cli_entry cli_config[]
Definition: main/config.c:4042