Asterisk - The Open Source Telephony Project  GIT-master-a24979a
Data Structures | Macros | Enumerations | Functions | Variables
main/config.c File Reference

Configuration File Parser. More...

#include "asterisk.h"
#include "asterisk/paths.h"
#include "asterisk/network.h"
#include <string.h>
#include <libgen.h>
#include <time.h>
#include <sys/stat.h>
#include <math.h>
#include <regex.h>
#include "asterisk/config.h"
#include "asterisk/cli.h"
#include "asterisk/lock.h"
#include "asterisk/utils.h"
#include "asterisk/channel.h"
#include "asterisk/app.h"
#include "asterisk/astobj2.h"
#include "asterisk/strings.h"
#include "asterisk/netsock2.h"
#include "asterisk/module.h"
Include dependency graph for main/config.c:

Go to the source code of this file.

Data Structures

struct  ast_category
 
struct  ast_category_template_instance
 
struct  ast_comment
 Structure to keep comments for rewriting configuration files. More...
 
struct  ast_config
 
struct  ast_config_include
 
struct  ast_config_map
 
struct  cache_file_include
 Hold the mtime for config files, so if we don't need to reread our config, don't. More...
 
struct  cache_file_mtime
 
struct  cfg_hook
 
struct  cfmtime_head
 
struct  inclfile
 
struct  cache_file_mtime::includes
 
struct  ast_category::template_instance_list
 

Macros

#define AST_MODULE   "extconfig"
 
#define CB_SIZE   250 /* initial size of comment buffers */
 
#define COMMENT_END   "--;"
 
#define COMMENT_META   ';'
 
#define COMMENT_START   ";--"
 
#define COMMENT_TAG   '-'
 
#define MAX_INCLUDE_LEVEL   10
 
#define MAX_NESTED_COMMENTS   128
 
#define MIN_VARIABLE_FNAME_SPACE   40
 
#define realtime_arguments_to_fields(ap, result)   realtime_arguments_to_fields2(ap, 0, result)
 
#define UTF8_BOM   "\xEF\xBB\xBF"
 

Enumerations

enum  config_cache_attribute_enum { ATTRIBUTE_INCLUDE = 0 , ATTRIBUTE_EXEC = 1 }
 

Functions

static void __init_appendbuf (void)
 
static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_variable_ast_variable_new (const char *name, const char *value, const char *filename, const char *file, const char *func, int lineno)
 
static struct ast_commentALLOC_COMMENT (struct ast_str *buffer)
 
void ast_category_append (struct ast_config *config, struct ast_category *category)
 Appends a category to a config. More...
 
char * ast_category_browse (struct ast_config *config, const char *prev_name)
 Browse categories. More...
 
struct ast_categoryast_category_browse_filtered (struct ast_config *config, const char *category_name, struct ast_category *prev, const char *filter)
 Browse categories with filters. More...
 
struct ast_categoryast_category_delete (struct ast_config *config, 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 *new, 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...
 
static void ast_comment_destroy (struct ast_comment **comment)
 
struct ast_configast_config_copy (const struct ast_config *old)
 Copies the contents of one ast_config into another. More...
 
void ast_config_destroy (struct ast_config *cfg)
 Destroys a config. More...
 
int ast_config_engine_deregister (struct ast_config_engine *del)
 Deregister config engine. More...
 
int ast_config_engine_register (struct ast_config_engine *new)
 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_cb)
 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 *filename, struct ast_config *cfg, struct ast_flags flags, const char *suggested_include_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 *configfile, 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 *configfile, 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,...)
 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...
 
static void ast_destroy_template_list (struct ast_category *cat)
 
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)
 
static void ast_includes_destroy (struct ast_config_include *incls)
 
struct ast_variableast_load_realtime (const char *family,...)
 
struct ast_variableast_load_realtime_all (const char *family,...)
 
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,...)
 Retrieve realtime configuration. More...
 
struct ast_configast_load_realtime_multientry_fields (const char *family, const struct ast_variable *fields)
 Retrieve realtime configuration. More...
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
int ast_parse_arg (const char *arg, enum ast_parse_flags flags, void *p_result,...)
 Helper function to parse arguments See documentation in config.h. More...
 
static int ast_realtime_append_mapping (const char *name, const char *driver, const char *database, const char *table, int priority)
 
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,...)
 Inform realtime what fields that may be stored. More...
 
int ast_store_realtime (const char *family,...)
 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,...)
 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,...)
 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)
 
int ast_variable_delete (struct ast_category *category, const char *variable, const char *match, const char *line)
 
static void ast_variable_destroy (struct ast_variable *doomed)
 
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 *newvar)
 Appends a variable list to the end of another list. More...
 
struct ast_variableast_variable_list_from_string (const char *input, const char *item_separator, const char *name_value_separator)
 Parse a string into an ast_variable list. The reverse of ast_variable_list_join. More...
 
struct ast_strast_variable_list_join (const struct ast_variable *head, const char *item_separator, const char *name_value_separator, const char *quote_char, struct ast_str **str)
 Join an ast_variable list with specified separators and quoted values. More...
 
int ast_variable_list_replace (struct ast_variable **head, struct ast_variable *replacement)
 Replace a variable in the given list with a new value. More...
 
int ast_variable_list_replace_variable (struct ast_variable **head, struct ast_variable *old, struct ast_variable *new)
 Replace a variable in the given list with a new variable. More...
 
struct ast_variableast_variable_list_sort (struct ast_variable *start)
 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...
 
static void ast_variable_move (struct ast_variable *dst_var, struct ast_variable *src_var)
 
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...
 
static struct ast_categorycategory_get_sep (const struct ast_config *config, const char *category_name, const char *filter, char sep, char pointer_match_possible)
 
static void CB_ADD (struct ast_str **cb, const char *str)
 
static void CB_ADD_LEN (struct ast_str **cb, const char *str, int len)
 
static void CB_RESET (struct ast_str *cb, struct ast_str *llb)
 
static int cfmstat_cmp (struct cache_file_mtime *cfmtime, struct stat *statbuf)
 
static void cfmstat_save (struct cache_file_mtime *cfmtime, struct stat *statbuf)
 
static struct cache_file_mtimecfmtime_new (const char *filename, const char *who_asked)
 
static void clear_config_maps (void)
 
static void config_cache_attribute (const char *configfile, enum config_cache_attribute_enum attrtype, const char *filename, const char *who_asked)
 
static void config_cache_destroy_entry (struct cache_file_mtime *cfmtime)
 
static void config_cache_flush_includes (struct cache_file_mtime *cfmtime)
 
static void config_cache_remove (const char *filename, const char *who_asked)
 
static void config_hook_exec (const char *filename, const char *module, const struct ast_config *cfg)
 
static void config_shutdown (void)
 
static struct ast_configconfig_text_file_load (const char *database, const char *table, const char *filename, struct ast_config *cfg, struct ast_flags flags, const char *suggested_include_file, const char *who_asked)
 
static int count_linefeeds (char *str)
 
static int count_linefeeds_in_comments (struct ast_comment *x)
 
static int does_category_match (struct ast_category *cat, const char *category_name, const char *match, char sep)
 Returns true if ALL of the regex expressions and category name match. Both can be NULL (I.E. no predicate) which results in a true return;. More...
 
static struct ast_config_enginefind_engine (const char *family, int priority, char *database, int dbsiz, char *table, int tabsiz)
 Find realtime engine for realtime family. More...
 
static void gen_header (FILE *f1, const char *configfile, const char *fn, const char *generator)
 
static char * handle_cli_config_list (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_cli_config_reload (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_cli_core_show_config_mappings (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static int hash_string (const void *obj, const int flags)
 
static int hashtab_compare_strings (void *a, void *b, int flags)
 
static int hook_cmp (void *obj, void *arg, int flags)
 
static void hook_destroy (void *obj)
 
static int hook_hash (const void *obj, const int flags)
 
static void inclfile_destroy (void *obj)
 
static int init_appendbuf (void *data)
 
static void insert_leading_blank_lines (FILE *fp, struct inclfile *fi, struct ast_comment *precomments, int lineno)
 
static int is_writable (const char *fn)
 
static int load_module (void)
 
static void make_fn (char *fn, size_t fn_size, const char *file, const char *configfile)
 
static void move_variables (struct ast_category *old, struct ast_category *new)
 
static struct ast_categorynew_category (const char *name, const char *in_file, int lineno, int template)
 
static struct ast_categorynext_available_category (struct ast_category *cat, const char *name, const char *filter)
 
static int process_text_line (struct ast_config *cfg, struct ast_category **cat, char *buf, int lineno, const char *configfile, struct ast_flags flags, struct ast_str *comment_buffer, struct ast_str *lline_buffer, const char *suggested_include_file, struct ast_category **last_cat, struct ast_variable **last_var, const char *who_asked)
 parse one line in the configuration. More...
 
static int realtime_arguments_to_fields2 (va_list ap, int skip, struct ast_variable **result)
 
int register_config_cli (void)
 Exposed initialization method for core process. More...
 
static int reload_module (void)
 
static struct inclfileset_fn (char *fn, size_t fn_size, const char *file, const char *configfile, struct ao2_container *fileset)
 
static int unload_module (void)
 
static struct ast_variablevariable_clone (const struct ast_variable *old)
 
static struct ast_variablevariable_list_switch (struct ast_variable *l1, struct ast_variable *l2)
 

Variables

static struct ast_module_info __mod_info = { .name = "extconfig" , .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "Configuration" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .reload = reload_module, .load_pri = 0, }
 
static struct ast_threadstorage appendbuf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_appendbuf , .custom_init = init_appendbuf , }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ao2_containercfg_hooks
 
static struct cfmtime_head cfmtime_head = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , }
 
static struct ast_cli_entry cli_config []
 
static struct ast_config_engineconfig_engine_list
 
static ast_mutex_t config_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
 
static struct ast_config_mapconfig_maps = NULL
 
static char * extconfig_conf = "extconfig.conf"
 
static struct ast_config_engine text_file_engine
 

Detailed Description

Configuration File Parser.

Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Includes the Asterisk Realtime API - ARA See http://wiki.asterisk.org

Definition in file main/config.c.

Macro Definition Documentation

◆ AST_MODULE

#define AST_MODULE   "extconfig"

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

◆ CB_SIZE

#define CB_SIZE   250 /* initial size of comment buffers */

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

◆ COMMENT_END

#define COMMENT_END   "--;"

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

◆ COMMENT_META

#define COMMENT_META   ';'

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

◆ COMMENT_START

#define COMMENT_START   ";--"

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

◆ COMMENT_TAG

#define COMMENT_TAG   '-'

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

◆ MAX_INCLUDE_LEVEL

#define MAX_INCLUDE_LEVEL   10

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

◆ MAX_NESTED_COMMENTS

#define MAX_NESTED_COMMENTS   128

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

◆ MIN_VARIABLE_FNAME_SPACE

#define MIN_VARIABLE_FNAME_SPACE   40

Define the minimum filename space to reserve for each ast_variable in case the filename is renamed later by ast_include_rename().

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

◆ realtime_arguments_to_fields

#define realtime_arguments_to_fields (   ap,
  result 
)    realtime_arguments_to_fields2(ap, 0, result)

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

◆ UTF8_BOM

#define UTF8_BOM   "\xEF\xBB\xBF"

Enumeration Type Documentation

◆ config_cache_attribute_enum

Enumerator
ATTRIBUTE_INCLUDE 
ATTRIBUTE_EXEC 

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

1654  {
1655  ATTRIBUTE_INCLUDE = 0,
1656  ATTRIBUTE_EXEC = 1,
1657 };
@ ATTRIBUTE_EXEC
Definition: main/config.c:1656
@ ATTRIBUTE_INCLUDE
Definition: main/config.c:1655

Function Documentation

◆ __init_appendbuf()

static void __init_appendbuf ( void  )
static

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

130 {

◆ __reg_module()

static void __reg_module ( void  )
static

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

◆ __unreg_module()

static void __unreg_module ( void  )
static

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

◆ _ast_variable_new()

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

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

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:1603
static const char name[]
Definition: format_mp3.c:68
#define MIN_VARIABLE_FNAME_SPACE
Definition: main/config.c:73
Structure for variables, used for configurations and for channel variables.
char stuff[0]
Contents of file, name, and value in that order stuffed here.
int value
Definition: syslog.c:37

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

◆ ALLOC_COMMENT()

static struct ast_comment* ALLOC_COMMENT ( struct ast_str buffer)
static

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

154 {
155  struct ast_comment *x = NULL;
156  if (!buffer || !ast_str_strlen(buffer)) {
157  return NULL;
158  }
159  if ((x = ast_calloc(1, sizeof(*x) + ast_str_strlen(buffer) + 1))) {
160  strcpy(x->cmt, ast_str_buffer(buffer)); /* SAFE */
161  }
162  return x;
163 }
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define NULL
Definition: resample.c:96
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:739
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:711
Structure to keep comments for rewriting configuration files.
Definition: main/config.c:84
char cmt[0]
Definition: main/config.c:87

References ast_calloc, ast_str_buffer(), ast_str_strlen(), ast_comment::cmt, and NULL.

Referenced by config_text_file_load(), and process_text_line().

◆ ast_category_append()

void ast_category_append ( struct ast_config config,
struct ast_category category 
)

Appends a category to a config.

Parameters
configwhich config to use
categorycategory to insert

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

1142 {
1143  if (config->last) {
1144  config->last->next = category;
1145  category->prev = config->last;
1146  } else {
1147  config->root = category;
1148  category->prev = NULL;
1149  }
1150  category->next = NULL;
1151  category->include_level = config->include_level;
1152 
1153  config->last = category;
1154  config->current = category;
1155 }
static const char config[]
Definition: chan_ooh323.c:111
struct ast_category * next
Definition: main/config.c:246
struct ast_category * prev
Definition: main/config.c:244

References config, ast_category::include_level, ast_category::next, NULL, and ast_category::prev.

Referenced by append_row_to_cfg(), ast_config_copy(), AST_TEST_DEFINE(), build_cfg(), config_curl(), config_ldap(), config_mysql(), config_odbc(), config_pgsql(), 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().

◆ ast_category_browse()

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

1364 {
1365  struct ast_category *cat;
1366 
1367  if (!prev_name) {
1368  /* First time browse. */
1369  cat = config->root;
1370  } else if (config->last_browse && (config->last_browse->name == prev_name)) {
1371  /* Simple last browse found. */
1372  cat = config->last_browse->next;
1373  } else {
1374  /*
1375  * Config changed since last browse.
1376  *
1377  * First try cheap last browse search. (Rebrowsing a different
1378  * previous category?)
1379  */
1380  for (cat = config->root; cat; cat = cat->next) {
1381  if (cat->name == prev_name) {
1382  /* Found it. */
1383  cat = cat->next;
1384  break;
1385  }
1386  }
1387  if (!cat) {
1388  /*
1389  * Have to do it the hard way. (Last category was deleted and
1390  * re-added?)
1391  */
1392  for (cat = config->root; cat; cat = cat->next) {
1393  if (!strcasecmp(cat->name, prev_name)) {
1394  /* Found it. */
1395  cat = cat->next;
1396  break;
1397  }
1398  }
1399  }
1400  }
1401 
1402  if (cat)
1403  cat = next_available_category(cat, NULL, NULL);
1404 
1405  config->last_browse = cat;
1406  return (cat) ? cat->name : NULL;
1407 }
static struct ast_category * next_available_category(struct ast_category *cat, const char *name, const char *filter)
Definition: main/config.c:1222
char name[80]
Definition: main/config.c:226

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

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(), load_common(), load_config(), load_module(), load_moh_classes(), load_odbc_config(), load_pktccops_config(), load_realtime_musiconhold(), load_realtime_queues(), load_realtime_rules(), load_tech_calendars(), load_users(), mbl_load_config(), 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_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().

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

1411 {
1412  struct ast_category *cat;
1413 
1414  if (!prev) {
1415  prev = config->root;
1416  } else {
1417  prev = prev->next;
1418  }
1419 
1420  cat = next_available_category(prev, category_name, filter);
1421 
1422  return cat;
1423 }
static int filter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:734

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

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

◆ ast_category_delete()

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

Delete a category.

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

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

1554 {
1555  struct ast_category *prev;
1556 
1557  if (!config || !category) {
1558  return NULL;
1559  }
1560 
1561  if (category->prev) {
1562  category->prev->next = category->next;
1563  } else {
1564  config->root = category->next;
1565  }
1566 
1567  if (category->next) {
1568  category->next->prev = category->prev;
1569  } else {
1570  config->last = category->prev;
1571  }
1572 
1573  prev = category->prev;
1574 
1575  if (config->last_browse == category) {
1576  config->last_browse = prev;
1577  }
1578 
1579  ast_category_destroy(category);
1580 
1581  return prev;
1582 }
void ast_category_destroy(struct ast_category *cat)
Definition: main/config.c:1196

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

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

◆ ast_category_destroy()

void ast_category_destroy ( struct ast_category cat)

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

1197 {
1199  cat->root = NULL;
1200  cat->last = NULL;
1205  ast_free(cat->file);
1206  ast_free(cat);
1207 }
#define ast_free(a)
Definition: astmm.h:180
static void ast_destroy_template_list(struct ast_category *cat)
Definition: main/config.c:1188
static void ast_comment_destroy(struct ast_comment **comment)
Definition: main/config.c:523
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: main/config.c:589
struct ast_comment * precomments
Definition: main/config.c:236
struct ast_variable * last
Definition: main/config.c:242
struct ast_comment * trailing
Definition: main/config.c:238
struct ast_variable * root
Definition: main/config.c:240
struct ast_comment * sameline
Definition: main/config.c:237
char * file
The file name from whence this declaration was read.
Definition: main/config.c:233

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

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

◆ ast_category_detach_variables()

struct ast_variable* ast_category_detach_variables ( struct ast_category cat)

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

1426 {
1427  struct ast_variable *v;
1428 
1429  v = cat->root;
1430  cat->root = NULL;
1431  cat->last = NULL;
1432 
1433  return v;
1434 }

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

Referenced by realtime_switch_common(), and sorcery_realtime_retrieve_multiple().

◆ ast_category_empty()

int ast_category_empty ( struct ast_category category)

Removes and destroys all variables in a category.

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

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

1585 {
1586  if (!category) {
1587  return -1;
1588  }
1589 
1590  ast_variables_destroy(category->root);
1591  category->root = NULL;
1592  category->last = NULL;
1593 
1594  return 0;
1595 }

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

Referenced by AST_TEST_DEFINE().

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

1137 {
1138  return !!ast_category_get(config, category_name, filter);
1139 }
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:1096

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

Referenced by realtime_sorcery_store().

◆ ast_category_first()

struct ast_variable* ast_category_first ( struct ast_category cat)

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

1098 {
1099  return category_get_sep(config, category_name, filter, ',', 1);
1100 }
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:1074

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

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

◆ ast_category_get_name()

const char* ast_category_get_name ( const struct ast_category category)

Return the name of the category.

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

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

1103 {
1104  return category->name;
1105 }

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

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

1113 {
1114  struct ast_category_template_instance *template;
1115  struct ast_str *str;
1116  int first = 1;
1117 
1118  if (AST_LIST_EMPTY(&category->template_instances)) {
1119  return NULL;
1120  }
1121 
1122  str = ast_str_create(128);
1123  if (!str) {
1124  return NULL;
1125  }
1126 
1127  AST_LIST_TRAVERSE(&category->template_instances, template, next) {
1128  ast_str_append(&str, 0, "%s%s", first ? "" : ",", template->name);
1129  first = 0;
1130  }
1131 
1132  return str;
1133 }
const char * str
Definition: app_jack.c:147
struct sla_ringing_trunk * first
Definition: app_meetme.c:1094
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:491
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:450
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:1117
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:640
struct ast_category_template_instance * next
Definition: main/config.c:222
struct ast_category::template_instance_list template_instances
Support for dynamic strings.
Definition: strings.h:604

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

Referenced by action_getconfig(), and action_getconfigjson().

◆ ast_category_inherit()

int ast_category_inherit ( struct ast_category existing,
const struct ast_category base 
)

Applies base (template) to category.

Parameters
existingexisting category
basebase category

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

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

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

1442 {
1443  struct ast_variable *var;
1445 
1446  x = ast_calloc(1, sizeof(*x));
1447  if (!x) {
1448  return -1;
1449  }
1450  strcpy(x->name, base->name);
1451  x->inst = base;
1453  for (var = base->root; var; var = var->next) {
1454  struct ast_variable *cloned = variable_clone(var);
1455  if (!cloned) {
1456  return -1;
1457  }
1458  cloned->inherited = 1;
1459  ast_variable_append(new, cloned);
1460  }
1461  return 0;
1462 }
#define var
Definition: ast_expr2f.c:614
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:731
void ast_variable_append(struct ast_category *category, struct ast_variable *variable)
Definition: main/config.c:486
static struct ast_variable * variable_clone(const struct ast_variable *old)
Definition: main/config.c:929
const struct ast_category * inst
Definition: main/config.c:221

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

Referenced by process_text_line().

◆ ast_category_insert()

int ast_category_insert ( struct ast_config config,
struct ast_category cat,
const char *  match 
)

Inserts new category.

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

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

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

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

1158 {
1159  struct ast_category *cur_category;
1160 
1161  if (!config || !config->root || !cat || !match) {
1162  return -1;
1163  }
1164 
1165  if (!strcasecmp(config->root->name, match)) {
1166  cat->next = config->root;
1167  cat->prev = NULL;
1168  config->root->prev = cat;
1169  config->root = cat;
1170  return 0;
1171  }
1172 
1173  for (cur_category = config->root->next; cur_category; cur_category = cur_category->next) {
1174  if (!strcasecmp(cur_category->name, match)) {
1175  cat->prev = cur_category->prev;
1176  cat->prev->next = cat;
1177 
1178  cat->next = cur_category;
1179  cur_category->prev = cat;
1180 
1181  return 0;
1182  }
1183  }
1184 
1185  return -1;
1186 }
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:2312

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

Referenced by AST_TEST_DEFINE().

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

1108 {
1109  return category->ignored;
1110 }

References ast_category::ignored.

Referenced by action_getconfig(), and action_getconfigjson().

◆ ast_category_new()

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

1065 {
1066  return new_category(name, in_file, lineno, 0);
1067 }
static struct ast_category * new_category(const char *name, const char *in_file, int lineno, int template)
Definition: main/config.c:1045

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

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

◆ ast_category_new_template()

struct ast_category* ast_category_new_template ( const char *  name,
const char *  in_file,
int  lineno 
)

Create a category making it a template.

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

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

1070 {
1071  return new_category(name, in_file, lineno, 1);
1072 }

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

Referenced by AST_TEST_DEFINE().

◆ ast_category_rename()

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

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

1437 {
1438  ast_copy_string(cat->name, name, sizeof(cat->name));
1439 }
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:406

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

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

◆ ast_category_root()

struct ast_variable* ast_category_root ( struct ast_config config,
char *  cat 
)

returns the root ast_variable of a config

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

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

1237 {
1238  struct ast_category *category = ast_category_get(config, cat, NULL);
1239 
1240  if (category)
1241  return category->root;
1242  return NULL;
1243 }

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

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

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

3430 {
3431  struct ast_config_engine *eng;
3432  if (!ast_realtime_enabled()) {
3433  return 0; /* There are no engines at all so fail early */
3434  }
3435 
3436  eng = find_engine(family, 1, NULL, 0, NULL, 0);
3437  if (eng)
3438  return 1;
3439  return 0;
3440 }
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:3108
int ast_realtime_enabled(void)
Check if there's any realtime engines loaded.
Definition: main/config.c:3443
Configuration engine structure, used to define realtime drivers.

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_queues(), load_realtime_rules(), local_ast_moh_start(), logger_queue_rt_start(), manager_queues_status(), manager_queues_summary(), msg_create_from_file(), realtime_peer(), realtime_update_peer(), register_realtime_peers_with_callbackextens(), rename_file(), set_member_paused(), set_member_value(), sip_poke_noanswer(), sip_show_settings(), and vm_delete().

◆ ast_comment_destroy()

static void ast_comment_destroy ( struct ast_comment **  comment)
static

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

524 {
525  struct ast_comment *n, *p;
526 
527  for (p = *comment; p; p = n) {
528  n = p->next;
529  ast_free(p);
530  }
531 
532  *comment = NULL;
533 }
#define comment
Definition: ael_lex.c:976
struct ast_comment * next
Definition: main/config.c:85

References ast_free, comment, ast_comment::next, and NULL.

Referenced by ast_category_destroy(), and ast_variable_destroy().

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

3146 {
3147  struct ast_config *new_config = ast_config_new();
3148  struct ast_category *cat_iter;
3149 
3150  if (!new_config) {
3151  return NULL;
3152  }
3153 
3154  for (cat_iter = old->root; cat_iter; cat_iter = cat_iter->next) {
3155  struct ast_category *new_cat =
3156  ast_category_new(cat_iter->name, cat_iter->file, cat_iter->lineno);
3157  if (!new_cat) {
3158  goto fail;
3159  }
3160  ast_category_append(new_config, new_cat);
3161  if (cat_iter->root) {
3162  new_cat->root = ast_variables_dup(cat_iter->root);
3163  if (!new_cat->root) {
3164  goto fail;
3165  }
3166  new_cat->last = cat_iter->last;
3167  }
3168  }
3169 
3170  return new_config;
3171 
3172 fail:
3173  ast_config_destroy(new_config);
3174  return NULL;
3175 }
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
Definition: main/config.c:1597
struct ast_config * ast_config_new(void)
Create a new base configuration structure.
Definition: main/config.c:1464
struct ast_variable * ast_variables_dup(struct ast_variable *var)
Duplicate variable list.
Definition: main/config.c:543
void ast_category_append(struct ast_config *config, struct ast_category *category)
Appends a category to a config.
Definition: main/config.c:1141
struct ast_category * ast_category_new(const char *name, const char *in_file, int lineno)
Create a category.
Definition: main/config.c:1064
struct ast_category * root
Definition: main/config.c:251

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

Referenced by AST_TEST_DEFINE(), and config_hook_exec().

◆ ast_config_destroy()

void ast_config_destroy ( struct ast_config cfg)

Destroys a config.

Parameters
cfgpointer to config data structure

Free memory associated with a given config

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

1598 {
1599  struct ast_category *cat, *catn;
1600 
1601  if (!cfg)
1602  return;
1603 
1605 
1606  cat = cfg->root;
1607  while (cat) {
1608  catn = cat;
1609  cat = cat->next;
1610  ast_category_destroy(catn);
1611  }
1612  ast_free(cfg);
1613 }
static void ast_includes_destroy(struct ast_config_include *incls)
Definition: main/config.c:1209
struct ast_config_include * includes
Definition: main/config.c:258

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

Referenced by __ast_http_load(), __ast_http_post_load(), __init_manager(), __queues_show(), _dsp_init(), 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_load(), config_module(), deinitialize_sorcery(), directory_exec(), 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(), init_logger_chain(), initialize_cc_devstate_map(), initialize_cc_max_requests(), load_asterisk_conf(), load_common(), load_config(), load_config_meetme(), load_module(), load_moh_classes(), load_odbc_config(), load_pktccops_config(), load_realtime_musiconhold(), load_realtime_queues(), load_realtime_rules(), load_users(), loader_config_init(), make_email_file(), mbl_load_config(), message_range_and_existence_check(), my_load_module(), named_acl_find_realtime(), notify_new_message(), object_type_loaded_observer(), odbc_load_module(), 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_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(), set_member_value(), setup_dahdi_int(), show_users_realtime(), sla_load_config(), smdi_load(), sorcery_config_internal_load(), sorcery_realtime_retrieve_multiple(), tds_load_module(), unload_module(), update_realtime_members(), vm_change_password(), vm_forwardoptions(), vm_msg_forward(), vm_msg_snapshot_create(), and write_password_to_file().

◆ ast_config_engine_deregister()

int ast_config_engine_deregister ( struct ast_config_engine del)

Deregister config engine.

Return values
0Always

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

3073 {
3074  struct ast_config_engine *ptr, *last=NULL;
3075 
3077 
3078  for (ptr = config_engine_list; ptr; ptr=ptr->next) {
3079  if (ptr == del) {
3080  if (last)
3081  last->next = ptr->next;
3082  else
3083  config_engine_list = ptr->next;
3084  break;
3085  }
3086  last = ptr;
3087  }
3088 
3089  return 0;
3090 }
ast_mutex_t lock
Definition: app_meetme.c:1093
struct sla_ringing_trunk * last
Definition: app_meetme.c:1094
#define SCOPED_MUTEX(varname, lock)
scoped lock specialization for mutexes
Definition: lock.h:587
static ast_mutex_t config_lock
Definition: main/config.c:214
static struct ast_config_engine * config_engine_list
Definition: main/config.c:215
struct ast_config_engine * next
struct sla_ringing_trunk * next
Definition: app_meetme.c:1070

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

Referenced by unload_module().

◆ ast_config_engine_register()

int ast_config_engine_register ( struct ast_config_engine newconfig)

Register config engine.

Return values
1Always

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

3057 {
3058  struct ast_config_engine *ptr;
3059 
3061 
3062  if (!config_engine_list) {
3063  config_engine_list = new;
3064  } else {
3065  for (ptr = config_engine_list; ptr->next; ptr=ptr->next);
3066  ptr->next = new;
3067  }
3068 
3069  return 1;
3070 }

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

Referenced by load_module().

◆ ast_config_get_current_category()

struct ast_category* ast_config_get_current_category ( const struct ast_config cfg)

Retrieve the current category name being built.

API for backend configuration engines while building a configuration set.

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

1616 {
1617  return cfg->current;
1618 }
struct ast_category * current
Definition: main/config.c:254

References ast_config::current.

Referenced by config_text_file_load().

◆ ast_config_hook_register()

int ast_config_hook_register ( const char *  name,
const char *  filename,
const char *  module,
enum config_hook_flags  flags,
config_hook_cb  hook 
)

Register a config hook for a particular file and module.

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

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

4206 {
4207  struct cfg_hook *hook;
4208  if (!cfg_hooks) {
4210  hook_hash, NULL, hook_cmp);
4211  if (!cfg_hooks) {
4212  return -1;
4213  }
4214  }
4215 
4216  if (!(hook = ao2_alloc(sizeof(*hook), hook_destroy))) {
4217  return -1;
4218  }
4219 
4220  hook->hook_cb = hook_cb;
4221  hook->filename = ast_strdup(filename);
4222  hook->name = ast_strdup(name);
4223  hook->module = ast_strdup(module);
4224 
4225  ao2_link(cfg_hooks, hook);
4226  ao2_ref(hook, -1);
4227  return 0;
4228 }
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ao2_link(container, obj)
Add an object to a container.
Definition: astobj2.h:1532
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition: astobj2.h:363
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
Definition: astobj2.h:1303
static int hook_hash(const void *obj, const int flags)
Definition: main/config.c:4166
static struct ao2_container * cfg_hooks
Definition: main/config.c:77
static void hook_destroy(void *obj)
Definition: main/config.c:4150
static int hook_cmp(void *obj, void *arg, int flags)
Definition: main/config.c:4158
config_hook_cb hook_cb
Definition: main/config.c:4147
const char * filename
Definition: main/config.c:4145
const char * module
Definition: main/config.c:4146
const char * name
Definition: main/config.c:4144
static int hook_cb(struct ast_config *cfg)
Definition: test_config.c:875

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

Referenced by AST_TEST_DEFINE().

◆ ast_config_hook_unregister()

void ast_config_hook_unregister ( const char *  name)

Unregister a config hook.

Parameters
nameThe name of the hook to unregister

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

4174 {
4175  struct cfg_hook tmp;
4176 
4177  tmp.name = ast_strdupa(name);
4178 
4180 }
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define OBJ_POINTER
Definition: astobj2.h:1150
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1736
@ OBJ_NODATA
Definition: astobj2.h:1044
@ OBJ_UNLINK
Definition: astobj2.h:1039
static int tmp()
Definition: bt_open.c:389

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

Referenced by AST_TEST_DEFINE().

◆ ast_config_internal_load()

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 at line 3178 of file main/config.c.

3179 {
3180  char db[256];
3181  char table[256];
3182  struct ast_config_engine *loader = &text_file_engine;
3183  struct ast_config *result;
3184 
3185  /* The config file itself bumps include_level by 1 */
3186  if (cfg->max_include_level > 0 && cfg->include_level == cfg->max_include_level + 1) {
3187  ast_log(LOG_WARNING, "Maximum Include level (%d) exceeded\n", cfg->max_include_level);
3188  return NULL;
3189  }
3190 
3191  cfg->include_level++;
3192 
3194  struct ast_config_engine *eng;
3195 
3196  eng = find_engine(filename, 1, db, sizeof(db), table, sizeof(table));
3197 
3198 
3199  if (eng && eng->load_func) {
3200  loader = eng;
3201  } else {
3202  eng = find_engine("global", 1, db, sizeof(db), table, sizeof(table));
3203  if (eng && eng->load_func)
3204  loader = eng;
3205  }
3206  }
3207 
3208  result = loader->load_func(db, table, filename, cfg, flags, suggested_include_file, who_asked);
3209 
3211  result->include_level--;
3212  config_hook_exec(filename, who_asked, result);
3213  } else if (result != CONFIG_STATUS_FILEINVALID) {
3214  cfg->include_level--;
3215  }
3216 
3217  return result;
3218 }
#define ast_log
Definition: astobj2.c:42
static char * table
Definition: cdr_odbc.c:55
static sqlite3 * db
static PGresult * result
Definition: cel_pgsql.c:84
@ CONFIG_FLAG_NOREALTIME
#define CONFIG_STATUS_FILEUNCHANGED
#define CONFIG_STATUS_FILEINVALID
#define LOG_WARNING
static void config_hook_exec(const char *filename, const char *module, const struct ast_config *cfg)
Definition: main/config.c:4182
static struct ast_config_engine text_file_engine
Definition: main/config.c:3140
config_load_func * load_func
int include_level
Definition: main/config.c:256
int max_include_level
Definition: main/config.c:257
#define ast_test_flag(p, flag)
Definition: utils.h:63

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

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

◆ ast_config_load2()

struct ast_config* ast_config_load2 ( const char *  filename,
const char *  who_asked,
struct ast_flags  flags 
)

Load a config file.

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

Create a config structure from a given configuration file.

Returns
an ast_config data structure on success
Return values
NULLon error

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

3221 {
3222  struct ast_config *cfg;
3223  struct ast_config *result;
3224 
3225  cfg = ast_config_new();
3226  if (!cfg)
3227  return NULL;
3228 
3229  result = ast_config_internal_load(filename, cfg, flags, "", who_asked);
3231  ast_config_destroy(cfg);
3232 
3233  return result;
3234 }
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:3178

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

◆ ast_config_new()

struct ast_config* ast_config_new ( void  )

◆ ast_config_option()

const char* ast_config_option ( struct ast_config cfg,
const char *  cat,
const char *  var 
)

Retrieve a configuration variable within the configuration set.

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

Returns
Value of var, or NULL if not found.

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

759 {
760  const char *tmp;
761  tmp = ast_variable_retrieve(cfg, cat, var);
762  if (!tmp) {
763  tmp = ast_variable_retrieve(cfg, "general", var);
764  }
765  return tmp;
766 }
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
Definition: main/config.c:768

References ast_variable_retrieve(), tmp(), and var.

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

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

1621 {
1622  /* cast below is just to silence compiler warning about dropping "const" */
1623  cfg->current = (struct ast_category *) cat;
1624 }

References ast_config::current.

Referenced by process_text_line().

◆ ast_config_sort_categories()

void ast_config_sort_categories ( struct ast_config config,
int  descending,
int(*)(struct ast_category *p, struct ast_category *q)  comparator 
)

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

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

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

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

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

References config, ast_category::next, and NULL.

Referenced by named_acl_find_realtime(), and realtime_switch_common().

◆ ast_config_text_file_save()

int ast_config_text_file_save ( const char *  filename,
const struct ast_config cfg,
const char *  generator 
)

Save a config text file preserving the pre 13.2 behavior.

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

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

2598 {
2599  return ast_config_text_file_save2(configfile, cfg, generator, CONFIG_SAVE_FLAG_PRESERVE_EFFECTIVE_CONTEXT);
2600 }
@ CONFIG_SAVE_FLAG_PRESERVE_EFFECTIVE_CONTEXT
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:2621

References ast_config_text_file_save2(), and CONFIG_SAVE_FLAG_PRESERVE_EFFECTIVE_CONTEXT.

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

◆ ast_config_text_file_save2()

int ast_config_text_file_save2 ( const char *  filename,
const struct ast_config cfg,
const char *  generator,
uint32_t  flags 
)

Save a config text file.

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

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

2622 {
2623  FILE *f;
2624  char fn[PATH_MAX];
2625  struct ast_variable *var;
2626  struct ast_category *cat;
2627  struct ast_comment *cmt;
2628  struct ast_config_include *incl;
2629  int blanklines = 0;
2630  struct ao2_container *fileset;
2631  struct inclfile *fi;
2632 
2635  if (!fileset) {
2636  /* Container creation failed. */
2637  return -1;
2638  }
2639 
2640  /* Check all the files for write access before attempting to modify any of them */
2641  for (incl = cfg->includes; incl; incl = incl->next) {
2642  /* reset all the output flags in case this isn't our first time saving this data */
2643  incl->output = 0;
2644 
2645  if (!incl->exec) {
2646  /* now make sure we have write access to the include file or its parent directory */
2647  make_fn(fn, sizeof(fn), incl->included_file, configfile);
2648  /* If the file itself doesn't exist, make sure we have write access to the directory */
2649  if (!is_writable(fn)) {
2650  return -1;
2651  }
2652  }
2653  }
2654 
2655  /* now make sure we have write access to the main config file or its parent directory */
2656  make_fn(fn, sizeof(fn), 0, configfile);
2657  if (!is_writable(fn)) {
2658  return -1;
2659  }
2660 
2661  /* Now that we know we have write access to all files, it's safe to start truncating them */
2662 
2663  /* go thru all the inclusions and make sure all the files involved (configfile plus all its inclusions)
2664  are all truncated to zero bytes and have that nice header*/
2665  for (incl = cfg->includes; incl; incl = incl->next) {
2666  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*/
2667  /* normally, fn is just set to incl->included_file, prepended with config dir if relative */
2668  fi = set_fn(fn, sizeof(fn), incl->included_file, configfile, fileset);
2669  f = fopen(fn, "w");
2670  if (f) {
2671  gen_header(f, configfile, fn, generator);
2672  fclose(f); /* this should zero out the file */
2673  } else {
2674  ast_log(LOG_ERROR, "Unable to write %s (%s)\n", fn, strerror(errno));
2675  }
2676  if (fi) {
2677  ao2_ref(fi, -1);
2678  }
2679  }
2680  }
2681 
2682  /* just set fn to absolute ver of configfile */
2683  fi = set_fn(fn, sizeof(fn), 0, configfile, fileset);
2684  if (
2685 #ifdef __CYGWIN__
2686  (f = fopen(fn, "w+"))
2687 #else
2688  (f = fopen(fn, "w"))
2689 #endif
2690  ) {
2691  ast_verb(2, "Saving '%s'\n", fn);
2692  gen_header(f, configfile, fn, generator);
2693  cat = cfg->root;
2694  fclose(f);
2695  if (fi) {
2696  ao2_ref(fi, -1);
2697  }
2698 
2699  /* from here out, we open each involved file and concat the stuff we need to add to the end and immediately close... */
2700  /* since each var, cat, and associated comments can come from any file, we have to be
2701  mobile, and open each file, print, and close it on an entry-by-entry basis */
2702 
2703  while (cat) {
2704  fi = set_fn(fn, sizeof(fn), cat->file, configfile, fileset);
2705  f = fopen(fn, "a");
2706  if (!f) {
2707  ast_log(LOG_ERROR, "Unable to write %s (%s)\n", fn, strerror(errno));
2708  if (fi) {
2709  ao2_ref(fi, -1);
2710  }
2711  ao2_ref(fileset, -1);
2712  return -1;
2713  }
2714 
2715  /* dump any includes that happen before this category header */
2716  for (incl=cfg->includes; incl; incl = incl->next) {
2717  if (strcmp(incl->include_location_file, cat->file) == 0){
2718  if (cat->lineno > incl->include_location_lineno && !incl->output) {
2719  if (incl->exec)
2720  fprintf(f,"#exec \"%s\"\n", incl->exec_file);
2721  else
2722  fprintf(f,"#include \"%s\"\n", incl->included_file);
2723  incl->output = 1;
2724  }
2725  }
2726  }
2727 
2728  insert_leading_blank_lines(f, fi, cat->precomments, cat->lineno);
2729  /* Dump section with any appropriate comment */
2730  for (cmt = cat->precomments; cmt; cmt=cmt->next) {
2731  char *cmtp = cmt->cmt;
2732  while (cmtp && *cmtp == ';' && *(cmtp+1) == '!') {
2733  char *cmtp2 = strchr(cmtp+1, '\n');
2734  if (cmtp2)
2735  cmtp = cmtp2+1;
2736  else cmtp = 0;
2737  }
2738  if (cmtp)
2739  fprintf(f,"%s", cmtp);
2740  }
2741  fprintf(f, "[%s]", cat->name);
2742  if (cat->ignored || !AST_LIST_EMPTY(&cat->template_instances)) {
2743  fprintf(f, "(");
2744  if (cat->ignored) {
2745  fprintf(f, "!");
2746  }
2747  if (cat->ignored && !AST_LIST_EMPTY(&cat->template_instances)) {
2748  fprintf(f, ",");
2749  }
2750  if (!AST_LIST_EMPTY(&cat->template_instances)) {
2753  fprintf(f,"%s",x->name);
2754  if (x != AST_LIST_LAST(&cat->template_instances))
2755  fprintf(f,",");
2756  }
2757  }
2758  fprintf(f, ")");
2759  }
2760  for(cmt = cat->sameline; cmt; cmt=cmt->next)
2761  {
2762  fprintf(f,"%s", cmt->cmt);
2763  }
2764  if (!cat->sameline)
2765  fprintf(f,"\n");
2766  for (cmt = cat->trailing; cmt; cmt=cmt->next) {
2767  if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
2768  fprintf(f,"%s", cmt->cmt);
2769  }
2770  fclose(f);
2771  if (fi) {
2772  ao2_ref(fi, -1);
2773  }
2774 
2775  var = cat->root;
2776  while (var) {
2778  int found = 0;
2779 
2781  struct ast_variable *v;
2782  for (v = x->inst->root; v; v = v->next) {
2783 
2785  if (!strcasecmp(var->name, v->name) && !strcmp(var->value, v->value)) {
2786  found = 1;
2787  break;
2788  }
2789  } else {
2790  if (var->inherited) {
2791  found = 1;
2792  break;
2793  } else {
2794  if (!strcasecmp(var->name, v->name) && !strcmp(var->value, v->value)) {
2795  found = 1;
2796  break;
2797  }
2798  }
2799  }
2800  }
2801  if (found) {
2802  break;
2803  }
2804  }
2805  if (found) {
2806  var = var->next;
2807  continue;
2808  }
2809  fi = set_fn(fn, sizeof(fn), var->file, configfile, fileset);
2810  f = fopen(fn, "a");
2811  if (!f) {
2812  ast_debug(1, "Unable to open for writing: %s\n", fn);
2813  ast_verb(2, "Unable to write %s (%s)\n", fn, strerror(errno));
2814  if (fi) {
2815  ao2_ref(fi, -1);
2816  }
2817  ao2_ref(fileset, -1);
2818  return -1;
2819  }
2820 
2821  /* dump any includes that happen before this category header */
2822  for (incl=cfg->includes; incl; incl = incl->next) {
2823  if (strcmp(incl->include_location_file, var->file) == 0){
2824  if (var->lineno > incl->include_location_lineno && !incl->output) {
2825  if (incl->exec)
2826  fprintf(f,"#exec \"%s\"\n", incl->exec_file);
2827  else
2828  fprintf(f,"#include \"%s\"\n", incl->included_file);
2829  incl->output = 1;
2830  }
2831  }
2832  }
2833 
2834  insert_leading_blank_lines(f, fi, var->precomments, var->lineno);
2835  for (cmt = var->precomments; cmt; cmt=cmt->next) {
2836  if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
2837  fprintf(f,"%s", cmt->cmt);
2838  }
2839 
2840  { /* Block for 'escaped' scope */
2841  int escaped_len = 2 * strlen(var->value) + 1;
2842  char escaped[escaped_len];
2843 
2844  ast_escape_semicolons(var->value, escaped, escaped_len);
2845 
2846  if (var->sameline) {
2847  fprintf(f, "%s %s %s %s", var->name, (var->object ? "=>" : "="),
2848  escaped, var->sameline->cmt);
2849  } else {
2850  fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="),
2851  escaped);
2852  }
2853  }
2854 
2855  for (cmt = var->trailing; cmt; cmt=cmt->next) {
2856  if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
2857  fprintf(f,"%s", cmt->cmt);
2858  }
2859  if (var->blanklines) {
2860  blanklines = var->blanklines;
2861  while (blanklines--)
2862  fprintf(f, "\n");
2863  }
2864 
2865  fclose(f);
2866  if (fi) {
2867  ao2_ref(fi, -1);
2868  }
2869 
2870  var = var->next;
2871  }
2872  cat = cat->next;
2873  }
2874  ast_verb(2, "Saving '%s': saved\n", fn);
2875  } else {
2876  ast_debug(1, "Unable to open for writing: %s\n", fn);
2877  ast_verb(2, "Unable to write '%s' (%s)\n", fn, strerror(errno));
2878  if (fi) {
2879  ao2_ref(fi, -1);
2880  }
2881  ao2_ref(fileset, -1);
2882  return -1;
2883  }
2884 
2885  /* Now, for files with trailing #include/#exec statements,
2886  we have to make sure every entry is output */
2887  for (incl=cfg->includes; incl; incl = incl->next) {
2888  if (!incl->output) {
2889  /* open the respective file */
2890  fi = set_fn(fn, sizeof(fn), incl->include_location_file, configfile, fileset);
2891  f = fopen(fn, "a");
2892  if (!f) {
2893  ast_debug(1, "Unable to open for writing: %s\n", fn);
2894  ast_verb(2, "Unable to write %s (%s)\n", fn, strerror(errno));
2895  if (fi) {
2896  ao2_ref(fi, -1);
2897  }
2898  ao2_ref(fileset, -1);
2899  return -1;
2900  }
2901 
2902  /* output the respective include */
2903  if (incl->exec)
2904  fprintf(f,"#exec \"%s\"\n", incl->exec_file);
2905  else
2906  fprintf(f,"#include \"%s\"\n", incl->included_file);
2907  fclose(f);
2908  incl->output = 1;
2909  if (fi) {
2910  ao2_ref(fi, -1);
2911  }
2912  }
2913  }
2914  ao2_ref(fileset, -1); /* this should destroy the hash container */
2915 
2916  /* pass new configuration to any config hooks */
2917  config_hook_exec(configfile, generator, cfg);
2918 
2919  return 0;
2920 }
#define PATH_MAX
Definition: asterisk.h:40
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
#define ast_verb(level,...)
#define AST_LIST_LAST(head)
Returns the last entry contained in a list.
Definition: linkedlists.h:429
static void insert_leading_blank_lines(FILE *fp, struct inclfile *fi, struct ast_comment *precomments, int lineno)
Definition: main/config.c:2561
static int hashtab_compare_strings(void *a, void *b, int flags)
Definition: main/config.c:193
static void gen_header(FILE *f1, const char *configfile, const char *fn, const char *generator)
Definition: main/config.c:2465
static int hash_string(const void *obj, const int flags)
Definition: main/config.c:173
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:2506
static int is_writable(const char *fn)
Definition: main/config.c:2602
static void make_fn(char *fn, size_t fn_size, const char *file, const char *configfile)
Definition: main/config.c:2491
int errno
Generic container type.
char * include_location_file
file name in which the include occurs
Definition: main/config.c:266
char * exec_file
if it's an exec, you'll have both the /var/tmp to read, and the original script
Definition: main/config.c:273
char * included_file
file name included
Definition: main/config.c:278
struct ast_config_include * next
Definition: main/config.c:282
struct ast_variable * next
char * ast_escape_semicolons(const char *string, char *outbuf, int buflen)
Escape semicolons found in a string.
Definition: main/utils.c:811

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

Referenced by action_updateconfig(), and ast_config_text_file_save().

◆ ast_destroy_realtime()

int ast_destroy_realtime ( const char *  family,
const char *  keyfield,
const char *  lookup,
  ... 
)

Destroy realtime configuration.

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

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

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

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

3676 {
3677  RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
3678  int res = 0;
3679  va_list ap;
3680 
3681  va_start(ap, lookup);
3682  if (realtime_arguments_to_fields(ap, &fields)) {
3683  res = -1;
3684  }
3685  va_end(ap);
3686 
3687  if (res) {
3688  return -1;
3689  }
3690 
3691  return ast_destroy_realtime_fields(family, keyfield, lookup, fields);
3692 }
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:3655
#define realtime_arguments_to_fields(ap, result)
Definition: main/config.c:3236
#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:936

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

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

◆ ast_destroy_realtime_fields()

int ast_destroy_realtime_fields ( const char *  family,
const char *  keyfield,
const char *  lookup,
const struct ast_variable fields 
)

Destroy realtime configuration.

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

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

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

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

3656 {
3657  struct ast_config_engine *eng;
3658  int res = -1, i;
3659  char db[256];
3660  char table[256];
3661 
3662  for (i = 1; ; i++) {
3663  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3664  if (eng->destroy_func && ((res = eng->destroy_func(db, table, keyfield, lookup, fields)) >= 0)) {
3665  break;
3666  }
3667  } else {
3668  break;
3669  }
3670  }
3671 
3672  return res;
3673 }
realtime_destroy * destroy_func

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

Referenced by ast_destroy_realtime(), and sorcery_realtime_delete().

◆ ast_destroy_template_list()

static void ast_destroy_template_list ( struct ast_category cat)
static

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

1189 {
1191 
1192  while ((x = AST_LIST_REMOVE_HEAD(&cat->template_instances, next)))
1193  ast_free(x);
1194 }
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:833

References ast_free, AST_LIST_REMOVE_HEAD, ast_category::next, and ast_category::template_instances.

Referenced by ast_category_destroy().

◆ ast_include_find()

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

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

476 {
477  struct ast_config_include *x;
478  for (x=conf->includes;x;x=x->next) {
479  if (strcmp(x->included_file,included_file) == 0)
480  return x;
481  }
482  return 0;
483 }
All configuration options for statsd client.
Definition: res_statsd.c:101

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

Referenced by ast_include_new().

◆ ast_include_new()

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

336 {
337  /* a file should be included ONCE. Otherwise, if one of the instances is changed,
338  * then all be changed. -- how do we know to include it? -- Handling modified
339  * instances is possible, I'd have
340  * to create a new master for each instance. */
341  struct ast_config_include *inc;
342  struct stat statbuf;
343 
344  inc = ast_include_find(conf, included_file);
345  if (inc) {
346  do {
347  inc->inclusion_count++;
348  snprintf(real_included_file_name, real_included_file_name_size, "%s~~%d", included_file, inc->inclusion_count);
349  } while (stat(real_included_file_name, &statbuf) == 0);
350  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);
351  } else
352  *real_included_file_name = 0;
353 
354  inc = ast_calloc(1,sizeof(struct ast_config_include));
355  if (!inc) {
356  return NULL;
357  }
358  inc->include_location_file = ast_strdup(from_file);
359  inc->include_location_lineno = from_lineno;
360  if (!ast_strlen_zero(real_included_file_name))
361  inc->included_file = ast_strdup(real_included_file_name);
362  else
363  inc->included_file = ast_strdup(included_file);
364 
365  inc->exec = is_exec;
366  if (is_exec)
367  inc->exec_file = ast_strdup(exec_file);
368 
369  if (!inc->include_location_file
370  || !inc->included_file
371  || (is_exec && !inc->exec_file)) {
373  return NULL;
374  }
375 
376  /* attach this new struct to the conf struct */
377  inc->next = conf->includes;
378  conf->includes = inc;
379 
380  return inc;
381 }
struct ast_config_include * ast_include_find(struct ast_config *conf, const char *included_file)
Definition: main/config.c:475
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65

References ast_calloc, ast_include_find(), ast_includes_destroy(), ast_log, ast_strdup, ast_strlen_zero(), ast_config_include::exec, ast_config_include::exec_file, ast_config_include::include_location_file, ast_config_include::include_location_lineno, ast_config_include::included_file, ast_config_include::inclusion_count, LOG_WARNING, ast_config_include::next, and NULL.

Referenced by AST_TEST_DEFINE(), and process_text_line().

◆ ast_include_rename()

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

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

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

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

Referenced by action_updateconfig().

◆ ast_includes_destroy()

static void ast_includes_destroy ( struct ast_config_include incls)
static

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

1210 {
1211  struct ast_config_include *incl,*inclnext;
1212 
1213  for (incl=incls; incl; incl = inclnext) {
1214  inclnext = incl->next;
1216  ast_free(incl->exec_file);
1217  ast_free(incl->included_file);
1218  ast_free(incl);
1219  }
1220 }

References ast_free, ast_config_include::exec_file, ast_config_include::include_location_file, ast_config_include::included_file, and ast_config_include::next.

Referenced by ast_config_destroy(), and ast_include_new().

◆ ast_load_realtime()

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

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

3406 {
3407  RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
3408  int field_res = 0;
3409  va_list ap;
3410 
3411  va_start(ap, family);
3412  if (realtime_arguments_to_fields(ap, &fields)) {
3413  field_res = -1;
3414  }
3415  va_end(ap);
3416 
3417  if (field_res) {
3418  return NULL;
3419  }
3420 
3421  if (!fields) {
3422  return NULL;
3423  }
3424 
3425  return ast_load_realtime_fields(family, fields);
3426 }
struct ast_variable * ast_load_realtime_fields(const char *family, const struct ast_variable *fields)
Retrieve realtime configuration.
Definition: main/config.c:3370

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(), and rt_extend_conf().

◆ ast_load_realtime_all()

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

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

3354 {
3355  RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
3356  struct ast_variable *res = NULL;
3357  va_list ap;
3358 
3359  va_start(ap, family);
3360  realtime_arguments_to_fields(ap, &fields);
3361  va_end(ap);
3362 
3363  if (fields) {
3364  res = ast_load_realtime_all_fields(family, fields);
3365  }
3366 
3367  return res;
3368 }
struct ast_variable * ast_load_realtime_all_fields(const char *family, const struct ast_variable *fields)
Definition: main/config.c:3332

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

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

◆ ast_load_realtime_all_fields()

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

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

3333 {
3334  struct ast_config_engine *eng;
3335  char db[256];
3336  char table[256];
3337  struct ast_variable *res=NULL;
3338  int i;
3339 
3340  for (i = 1; ; i++) {
3341  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3342  if (eng->realtime_func && (res = eng->realtime_func(db, table, fields))) {
3343  return res;
3344  }
3345  } else {
3346  return NULL;
3347  }
3348  }
3349 
3350  return res;
3351 }
realtime_var_get * realtime_func

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

Referenced by ast_load_realtime_all(), and ast_load_realtime_fields().

◆ ast_load_realtime_fields()

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

Retrieve realtime configuration.

Parameters
familywhich family/config to lookup
fieldswhich fields to lookup

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

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

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

3371 {
3372  struct ast_variable *res;
3373  struct ast_variable *cur;
3374  struct ast_variable **prev;
3375 
3376  res = ast_load_realtime_all_fields(family, fields);
3377 
3378  /* Filter the list. */
3379  prev = &res;
3380  cur = res;
3381  while (cur) {
3382  if (ast_strlen_zero(cur->value)) {
3383  /* Eliminate empty entries */
3384  struct ast_variable *next;
3385 
3386  next = cur->next;
3387  *prev = next;
3388  ast_variable_destroy(cur);
3389  cur = next;
3390  } else {
3391  /* Make blank entries empty and keep them. */
3392  if (cur->value[0] == ' ' && cur->value[1] == '\0') {
3393  char *vptr = (char *) cur->value;
3394 
3395  vptr[0] = '\0';
3396  }
3397 
3398  prev = &cur->next;
3399  cur = cur->next;
3400  }
3401  }
3402  return res;
3403 }

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

Referenced by ast_load_realtime(), and sorcery_realtime_retrieve_fields().

◆ ast_load_realtime_multientry()

struct ast_config* ast_load_realtime_multientry ( const char *  family,
  ... 
)

Retrieve realtime configuration.

Parameters
familywhich family/config to lookup

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

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

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

3522 {
3523  RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
3524  va_list ap;
3525 
3526  va_start(ap, family);
3527  realtime_arguments_to_fields(ap, &fields);
3528  va_end(ap);
3529 
3530  if (!fields) {
3531  return NULL;
3532  }
3533 
3534  return ast_load_realtime_multientry_fields(family, fields);
3535 }
struct ast_config * ast_load_realtime_multientry_fields(const char *family, const struct ast_variable *fields)
Retrieve realtime configuration.
Definition: main/config.c:3495

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_realtime_musiconhold(), load_realtime_queues(), 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().

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

3496 {
3497  struct ast_config_engine *eng;
3498  char db[256];
3499  char table[256];
3500  struct ast_config *res = NULL;
3501  int i;
3502 
3503  for (i = 1; ; i++) {
3504  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3505  if (eng->realtime_multi_func && (res = eng->realtime_multi_func(db, table, fields))) {
3506  /* If we were returned an empty cfg, destroy it and return NULL */
3507  if (!res->root) {
3508  ast_config_destroy(res);
3509  res = NULL;
3510  }
3511  break;
3512  }
3513  } else {
3514  break;
3515  }
3516  }
3517 
3518  return res;
3519 }
realtime_multi_get * realtime_multi_func

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

Referenced by ast_load_realtime_multientry(), and sorcery_realtime_retrieve_multiple().

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

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

◆ ast_parse_arg()

int ast_parse_arg ( const char *  arg,
enum ast_parse_flags  flags,
void *  p_result,
  ... 
)

Helper function to parse arguments See documentation in config.h.

The argument parsing routine.

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

3728 {
3729  va_list ap;
3730  int error = 0;
3731 
3732  va_start(ap, p_result);
3733  switch (flags & PARSE_TYPE) {
3734  case PARSE_INT32:
3735  {
3736  long int x = 0;
3737  int32_t *result = p_result;
3738  int32_t def = result ? *result : 0, high = INT32_MAX, low = INT32_MIN;
3739  char *endptr = NULL;
3740 
3741  /* optional arguments: default value and/or (low, high) */
3742  if (flags & PARSE_DEFAULT) {
3743  def = va_arg(ap, int32_t);
3744  }
3745  if (flags & (PARSE_IN_RANGE | PARSE_OUT_RANGE)) {
3746  low = va_arg(ap, int32_t);
3747  high = va_arg(ap, int32_t);
3748  }
3749  if (ast_strlen_zero(arg)) {
3750  error = 1;
3751  goto int32_done;
3752  }
3753  errno = 0;
3754  x = strtol(arg, &endptr, 0);
3755  if (*endptr || errno || x < INT32_MIN || x > INT32_MAX) {
3756  /* Parse error, or type out of int32_t bounds */
3757  error = 1;
3758  goto int32_done;
3759  }
3760  error = (x < low) || (x > high);
3761  if (flags & PARSE_RANGE_DEFAULTS) {
3762  if (x < low) {
3763  def = low;
3764  } else if (x > high) {
3765  def = high;
3766  }
3767  }
3768  if (flags & PARSE_OUT_RANGE) {
3769  error = !error;
3770  }
3771 int32_done:
3772  if (result) {
3773  *result = error ? def : x;
3774  }
3775 
3776  ast_debug(3, "extract int from [%s] in [%d, %d] gives [%ld](%d)\n",
3777  arg, low, high, result ? *result : x, error);
3778  break;
3779  }
3780 
3781  case PARSE_UINT32:
3782  {
3783  unsigned long int x = 0;
3784  uint32_t *result = p_result;
3785  uint32_t def = result ? *result : 0, low = 0, high = UINT32_MAX;
3786  char *endptr = NULL;
3787 
3788  /* optional argument: first default value, then range */
3789  if (flags & PARSE_DEFAULT) {
3790  def = va_arg(ap, uint32_t);
3791  }
3792  if (flags & (PARSE_IN_RANGE|PARSE_OUT_RANGE)) {
3793  /* range requested, update bounds */
3794  low = va_arg(ap, uint32_t);
3795  high = va_arg(ap, uint32_t);
3796  }
3797 
3798  if (ast_strlen_zero(arg)) {
3799  error = 1;
3800  goto uint32_done;
3801  }
3802  /* strtoul will happily and silently negate negative numbers */
3803  arg = ast_skip_blanks(arg);
3804  if (*arg == '-') {
3805  error = 1;
3806  goto uint32_done;
3807  }
3808  errno = 0;
3809  x = strtoul(arg, &endptr, 0);
3810  if (*endptr || errno || x > UINT32_MAX) {
3811  error = 1;
3812  goto uint32_done;
3813  }
3814  error = (x < low) || (x > high);
3815  if (flags & PARSE_RANGE_DEFAULTS) {
3816  if (x < low) {
3817  def = low;
3818  } else if (x > high) {
3819  def = high;
3820  }
3821  }
3822  if (flags & PARSE_OUT_RANGE) {
3823  error = !error;
3824  }
3825 uint32_done:
3826  if (result) {
3827  *result = error ? def : x;
3828  }
3829  ast_debug(3, "extract uint from [%s] in [%u, %u] gives [%lu](%d)\n",
3830  arg, low, high, result ? *result : x, error);
3831  break;
3832  }
3833 
3834  case PARSE_TIMELEN:
3835  {
3836  int x = 0;
3837  int *result = p_result;
3838  int def = result ? *result : 0;
3839  int high = INT_MAX;
3840  int low = INT_MIN;
3841  enum ast_timelen defunit;
3842 
3843  defunit = va_arg(ap, enum ast_timelen);
3844  /* optional arguments: default value and/or (low, high) */
3845  if (flags & PARSE_DEFAULT) {
3846  def = va_arg(ap, int);
3847  }
3848  if (flags & (PARSE_IN_RANGE | PARSE_OUT_RANGE)) {
3849  low = va_arg(ap, int);
3850  high = va_arg(ap, int);
3851  }
3852  if (ast_strlen_zero(arg)) {
3853  error = 1;
3854  goto timelen_done;
3855  }
3856  error = ast_app_parse_timelen(arg, &x, defunit);
3857  if (error || x < INT_MIN || x > INT_MAX) {
3858  /* Parse error, or type out of int bounds */
3859  error = 1;
3860  goto timelen_done;
3861  }
3862  error = (x < low) || (x > high);
3863  if (flags & PARSE_RANGE_DEFAULTS) {
3864  if (x < low) {
3865  def = low;
3866  } else if (x > high) {
3867  def = high;
3868  }
3869  }
3870  if (flags & PARSE_OUT_RANGE) {
3871  error = !error;
3872  }
3873 timelen_done:
3874  if (result) {
3875  *result = error ? def : x;
3876  }
3877 
3878  ast_debug(3, "extract timelen from [%s] in [%d, %d] gives [%d](%d)\n",
3879  arg, low, high, result ? *result : x, error);
3880  break;
3881  }
3882 
3883  case PARSE_DOUBLE:
3884  {
3885  double *result = p_result;
3886  double x = 0, def = result ? *result : 0, low = -HUGE_VAL, high = HUGE_VAL;
3887  char *endptr = NULL;
3888 
3889  /* optional argument: first default value, then range */
3890  if (flags & PARSE_DEFAULT) {
3891  def = va_arg(ap, double);
3892  }
3893  if (flags & (PARSE_IN_RANGE | PARSE_OUT_RANGE)) {
3894  /* range requested, update bounds */
3895  low = va_arg(ap, double);
3896  high = va_arg(ap, double);
3897  }
3898  if (ast_strlen_zero(arg)) {
3899  error = 1;
3900  goto double_done;
3901  }
3902  errno = 0;
3903  x = strtod(arg, &endptr);
3904  if (*endptr || errno == ERANGE) {
3905  error = 1;
3906  goto double_done;
3907  }
3908  error = (x < low) || (x > high);
3909  if (flags & PARSE_OUT_RANGE) {
3910  error = !error;
3911  }
3912 double_done:
3913  if (result) {
3914  *result = error ? def : x;
3915  }
3916  ast_debug(3, "extract double from [%s] in [%f, %f] gives [%f](%d)\n",
3917  arg, low, high, result ? *result : x, error);
3918  break;
3919  }
3920  case PARSE_ADDR:
3921  {
3922  struct ast_sockaddr *addr = (struct ast_sockaddr *)p_result;
3923 
3924  if (!ast_sockaddr_parse(addr, arg, flags & PARSE_PORT_MASK)) {
3925  error = 1;
3926  }
3927 
3928  ast_debug(3, "extract addr from %s gives %s(%d)\n",
3929  arg, ast_sockaddr_stringify(addr), error);
3930 
3931  break;
3932  }
3933  case PARSE_INADDR: /* TODO Remove this (use PARSE_ADDR instead). */
3934  {
3935  char *port, *buf;
3936  struct sockaddr_in _sa_buf; /* buffer for the result */
3937  struct sockaddr_in *sa = p_result ?
3938  (struct sockaddr_in *)p_result : &_sa_buf;
3939  /* default is either the supplied value or the result itself */
3940  struct sockaddr_in *def = (flags & PARSE_DEFAULT) ?
3941  va_arg(ap, struct sockaddr_in *) : sa;
3942  struct ast_sockaddr addr = { {0,} };
3943 
3944  memset(&_sa_buf, '\0', sizeof(_sa_buf)); /* clear buffer */
3945  /* duplicate the string to strip away the :port */
3946  port = ast_strdupa(arg);
3947  buf = strsep(&port, ":");
3948  sa->sin_family = AF_INET; /* assign family */
3949  /*
3950  * honor the ports flag setting, assign default value
3951  * in case of errors or field unset.
3952  */
3953  flags &= PARSE_PORT_MASK; /* the only flags left to process */
3954  if (port) {
3955  if (flags == PARSE_PORT_FORBID) {
3956  error = 1; /* port was forbidden */
3957  sa->sin_port = def->sin_port;
3958  } else if (flags == PARSE_PORT_IGNORE)
3959  sa->sin_port = def->sin_port;
3960  else /* accept or require */
3961  sa->sin_port = htons(strtol(port, NULL, 0));
3962  } else {
3963  sa->sin_port = def->sin_port;
3964  if (flags == PARSE_PORT_REQUIRE)
3965  error = 1;
3966  }
3967  /* Now deal with host part, even if we have errors before. */
3968  if (ast_sockaddr_resolve_first_af(&addr, buf, PARSE_PORT_FORBID, AF_INET)) {
3969  error = 1;
3970  sa->sin_addr = def->sin_addr;
3971  } else {
3972  struct sockaddr_in tmp;
3973  ast_sockaddr_to_sin(&addr, &tmp);
3974  sa->sin_addr = tmp.sin_addr;
3975  }
3976  ast_debug(3,
3977  "extract inaddr from [%s] gives [%s:%d](%d)\n",
3978  arg, ast_inet_ntoa(sa->sin_addr),
3979  ntohs(sa->sin_port), error);
3980  break;
3981  }
3982  }
3983  va_end(ap);
3984  return error;
3985 }
#define INT32_MAX
Definition: ast_expr2f.c:78
#define INT32_MIN
Definition: ast_expr2f.c:69
#define UINT32_MAX
Definition: ast_expr2f.c:87
int int32_t
Definition: db.h:60
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
int ast_app_parse_timelen(const char *timestr, int *result, enum ast_timelen defunit)
Common routine to parse time lengths, with optional time unit specifier.
Definition: main/app.c:3333
char * strsep(char **str, const char *delims)
@ PARSE_RANGE_DEFAULTS
@ PARSE_PORT_REQUIRE
int ast_sockaddr_resolve_first_af(struct ast_sockaddr *addr, const char *name, int flag, int family)
Return the first entry from ast_sockaddr_resolve filtered by address family.
Definition: netsock2.c:337
#define ast_sockaddr_to_sin(addr, sin)
Converts a struct ast_sockaddr to a struct sockaddr_in.
Definition: netsock2.h:765
int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
Parse an IPv4 or IPv6 address string.
Definition: netsock2.c:230
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition: netsock2.h:256
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
Definition: main/utils.c:928
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
Definition: strings.h:161
Socket address structure.
Definition: netsock2.h:97
int error(const char *format,...)
Definition: utils/frame.c:999

References ast_app_parse_timelen(), ast_debug, ast_inet_ntoa(), ast_skip_blanks(), ast_sockaddr_parse(), ast_sockaddr_resolve_first_af(), ast_sockaddr_stringify(), ast_sockaddr_to_sin, ast_strdupa, ast_strlen_zero(), buf, errno, error(), INT32_MAX, INT32_MIN, NULL, PARSE_ADDR, PARSE_DEFAULT, PARSE_DOUBLE, PARSE_IN_RANGE, PARSE_INADDR, PARSE_INT32, PARSE_OUT_RANGE, PARSE_PORT_FORBID, PARSE_PORT_IGNORE, PARSE_PORT_MASK, PARSE_PORT_REQUIRE, PARSE_RANGE_DEFAULTS, PARSE_TIMELEN, PARSE_TYPE, PARSE_UINT32, result, strsep(), tmp(), 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(), 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().

◆ ast_realtime_append_mapping()

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

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

2938 {
2939  struct ast_config_map *map;
2940  char *dst;
2941  int length;
2942 
2943  length = sizeof(*map);
2944  length += strlen(name) + 1;
2945  length += strlen(driver) + 1;
2946  length += strlen(database) + 1;
2947  if (table)
2948  length += strlen(table) + 1;
2949 
2950  if (!(map = ast_calloc(1, length)))
2951  return -1;
2952 
2953  dst = map->stuff; /* writable space starts here */
2954  map->name = strcpy(dst, name);
2955  dst += strlen(dst) + 1;
2956  map->driver = strcpy(dst, driver);
2957  dst += strlen(dst) + 1;
2958  map->database = strcpy(dst, database);
2959  if (table) {
2960  dst += strlen(dst) + 1;
2961  map->table = strcpy(dst, table);
2962  }
2963  map->priority = priority;
2964  map->next = config_maps;
2965  config_maps = map;
2966 
2967  ast_verb(2, "Binding %s to %s/%s/%s\n", map->name, map->driver, map->database, map->table ? map->table : map->name);
2968 
2969  return 0;
2970 }
static int priority
static struct ast_config_map * config_maps
const char * driver
Definition: main/config.c:205
struct ast_config_map * next
Definition: main/config.c:200
const char * table
Definition: main/config.c:209
const char * database
Definition: main/config.c:207
const char * name
Definition: main/config.c:203

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

Referenced by reload_module().

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

3695 {
3696  char *orig = chunk;
3697  for (; *chunk; chunk++) {
3698  if (*chunk == '^' && strchr("0123456789ABCDEFabcdef", chunk[1]) && strchr("0123456789ABCDEFabcdef", chunk[2])) {
3699  sscanf(chunk + 1, "%02hhX", (unsigned char *)chunk);
3700  memmove(chunk + 1, chunk + 3, strlen(chunk + 3) + 1);
3701  }
3702  }
3703  return orig;
3704 }

Referenced by realtime_multi_pgsql(), and realtime_pgsql().

◆ ast_realtime_enabled()

int ast_realtime_enabled ( void  )

Check if there's any realtime engines loaded.

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

3444 {
3445  return config_maps ? 1 : 0;
3446 }

References config_maps.

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

◆ ast_realtime_encode_chunk()

char* ast_realtime_encode_chunk ( struct ast_str **  dest,
ssize_t  maxlen,
const char *  chunk 
)

Encodes a chunk of data for realtime.

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

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

3707 {
3708  if (!strchr(chunk, ';') && !strchr(chunk, '^')) {
3709  ast_str_set(dest, maxlen, "%s", chunk);
3710  } else {
3711  ast_str_reset(*dest);
3712  for (; *chunk; chunk++) {
3713  if (strchr(";^", *chunk)) {
3714  ast_str_append(dest, maxlen, "^%02hhX", *chunk);
3715  } else {
3716  ast_str_append(dest, maxlen, "%c", *chunk);
3717  }
3718  }
3719  }
3720  return ast_str_buffer(*dest);
3721 }
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:674
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:1091

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

◆ ast_realtime_is_mapping_defined()

int ast_realtime_is_mapping_defined ( const char *  family)

Determine if a mapping exists for a given family.

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

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

3093 {
3094  struct ast_config_map *map;
3096 
3097  for (map = config_maps; map; map = map->next) {
3098  if (!strcasecmp(family, map->name)) {
3099  return 1;
3100  }
3101  }
3102  ast_debug(5, "Failed to find a realtime mapping for %s\n", family);
3103 
3104  return 0;
3105 }

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

Referenced by ast_named_acl_find(), and sorcery_realtime_open().

◆ ast_realtime_require_field()

int ast_realtime_require_field ( const char *  family,
  ... 
)

Inform realtime what fields that may be stored.

Since
1.6.1
Parameters
familywhich family/config is referenced

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

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

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

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

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

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

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

3449 {
3450  struct ast_config_engine *eng;
3451  char db[256];
3452  char table[256];
3453  va_list ap, aq;
3454  int res = -1, i;
3455 
3456  va_start(ap, family);
3457  for (i = 1; ; i++) {
3458  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3459  va_copy(aq, ap);
3460  /* If the require succeeds, it returns 0. */
3461  if (eng->require_func && !(res = eng->require_func(db, table, aq))) {
3462  va_end(aq);
3463  break;
3464  }
3465  va_end(aq);
3466  } else {
3467  break;
3468  }
3469  }
3470  va_end(ap);
3471 
3472  return res;
3473 }
realtime_require * require_func

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

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

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

3640 {
3641  RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
3642  va_list ap;
3643 
3644  va_start(ap, family);
3645  realtime_arguments_to_fields(ap, &fields);
3646  va_end(ap);
3647 
3648  if (!fields) {
3649  return -1;
3650  }
3651 
3652  return ast_store_realtime_fields(family, fields);
3653 }
int ast_store_realtime_fields(const char *family, const struct ast_variable *fields)
Create realtime configuration.
Definition: main/config.c:3618

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

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

◆ ast_store_realtime_fields()

int ast_store_realtime_fields ( const char *  family,
const struct ast_variable fields 
)

Create realtime configuration.

Parameters
familywhich family/config to be created
fieldsfields themselves

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

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

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

3619 {
3620  struct ast_config_engine *eng;
3621  int res = -1, i;
3622  char db[256];
3623  char table[256];
3624 
3625  for (i = 1; ; i++) {
3626  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3627  /* If the store succeeds, it returns >= 0*/
3628  if (eng->store_func && ((res = eng->store_func(db, table, fields)) >= 0)) {
3629  break;
3630  }
3631  } else {
3632  break;
3633  }
3634  }
3635 
3636  return res;
3637 }
realtime_store * store_func

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

Referenced by ast_store_realtime(), and sorcery_realtime_create().

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

3476 {
3477  struct ast_config_engine *eng;
3478  char db[256];
3479  char table[256];
3480  int res = -1, i;
3481 
3482  for (i = 1; ; i++) {
3483  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3484  if (eng->unload_func) {
3485  /* Do this for ALL engines */
3486  res = eng->unload_func(db, table);
3487  }
3488  } else {
3489  break;
3490  }
3491  }
3492  return res;
3493 }
realtime_unload * unload_func

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

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

◆ ast_update2_realtime()

int ast_update2_realtime ( const char *  family,
  ... 
)

Update realtime configuration.

Parameters
familywhich family/config to be updated

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

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

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

3595 {
3596  RAII_VAR(struct ast_variable *, lookup_fields, NULL, ast_variables_destroy);
3597  RAII_VAR(struct ast_variable *, update_fields, NULL, ast_variables_destroy);
3598  va_list ap;
3599 
3600  va_start(ap, family);
3601  /* XXX: If we wanted to pass no lookup fields (select all), we'd be
3602  * out of luck. realtime_arguments_to_fields expects at least one key
3603  * value pair. */
3604  realtime_arguments_to_fields(ap, &lookup_fields);
3605  va_end(ap);
3606 
3607  va_start(ap, family);
3608  realtime_arguments_to_fields2(ap, 1, &update_fields);
3609  va_end(ap);
3610 
3611  if (!lookup_fields || !update_fields) {
3612  return -1;
3613  }
3614 
3615  return ast_update2_realtime_fields(family, lookup_fields, update_fields);
3616 }
static int realtime_arguments_to_fields2(va_list ap, int skip, struct ast_variable **result)
Definition: main/config.c:3251
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:3574

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

Referenced by change_password_realtime(), and cli_realtime_update2().

◆ ast_update2_realtime_fields()

int ast_update2_realtime_fields ( const char *  family,
const struct ast_variable lookup_fields,
const struct ast_variable update_fields 
)

Update realtime configuration.

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

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

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

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

3575 {
3576  struct ast_config_engine *eng;
3577  int res = -1, i;
3578  char db[256];
3579  char table[256];
3580 
3581  for (i = 1; ; i++) {
3582  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3583  if (eng->update2_func && !(res = eng->update2_func(db, table, lookup_fields, update_fields))) {
3584  break;
3585  }
3586  } else {
3587  break;
3588  }
3589  }
3590 
3591  return res;
3592 }
realtime_update2 * update2_func

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

Referenced by ast_update2_realtime().

◆ ast_update_realtime()

int ast_update_realtime ( const char *  family,
const char *  keyfield,
const char *  lookup,
  ... 
)

Update realtime configuration.

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

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

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

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

3559 {
3560  RAII_VAR(struct ast_variable *, fields, NULL, ast_variables_destroy);
3561  va_list ap;
3562 
3563  va_start(ap, lookup);
3564  realtime_arguments_to_fields(ap, &fields);
3565  va_end(ap);
3566 
3567  if (!fields) {
3568  return -1;
3569  }
3570 
3571  return ast_update_realtime_fields(family, keyfield, lookup, fields);
3572 }
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:3537

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

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

3538 {
3539  struct ast_config_engine *eng;
3540  int res = -1, i;
3541  char db[256];
3542  char table[256];
3543 
3544  for (i = 1; ; i++) {
3545  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
3546  /* If the update succeeds, it returns >= 0. */
3547  if (eng->update_func && ((res = eng->update_func(db, table, keyfield, lookup, fields)) >= 0)) {
3548  break;
3549  }
3550  } else {
3551  break;
3552  }
3553  }
3554 
3555  return res;
3556 }
realtime_update * update_func

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

Referenced by ast_update_realtime(), and sorcery_realtime_update().

◆ ast_variable_append()

void ast_variable_append ( struct ast_category category,
struct ast_variable variable 
)

◆ ast_variable_browse()

struct ast_variable* ast_variable_browse ( const struct ast_config config,
const char *  category 
)

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

601 {
602  struct ast_category *cat;
603 
604  if (config->last_browse && (config->last_browse->name == category)) {
605  cat = config->last_browse;
606  } else {
607  cat = ast_category_get(config, category, NULL);
608  }
609 
610  return (cat) ? cat->root : NULL;
611 }

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

Referenced by __ast_http_load(), __ast_http_post_load(), __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_say(), ewscal_load_calendar(), exchangecal_load_calendar(), find_conf(), get_defaults(), handle_cli_dialplan_save(), iax_template_parse(), ical_load_calendar(), init_logger_chain(), load_aliases(), load_asterisk_conf(), load_common(), load_config(), load_general_config(), load_moh_classes(), load_odbc_config(), load_pktccops_config(), load_users(), load_zonemessages(), loader_config_init(), mbl_load_adapter(), mbl_load_config(), mbl_load_device(), 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(), tds_load_module(), and test_config_validity().

◆ ast_variable_delete()

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

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

1474 {
1475  struct ast_variable *cur, *prev=NULL, *curn;
1476  int res = -1;
1477  int num_item = 0;
1478  int req_item;
1479 
1480  req_item = -1;
1481  if (!ast_strlen_zero(line)) {
1482  /* Requesting to delete by item number. */
1483  if (sscanf(line, "%30d", &req_item) != 1
1484  || req_item < 0) {
1485  /* Invalid item number to delete. */
1486  return -1;
1487  }
1488  }
1489 
1490  prev = NULL;
1491  cur = category->root;
1492  while (cur) {
1493  curn = cur->next;
1494  /* Delete by item number or by variable name with optional value. */
1495  if ((0 <= req_item && num_item == req_item)
1496  || (req_item < 0 && !strcasecmp(cur->name, variable)
1497  && (ast_strlen_zero(match) || !strcasecmp(cur->value, match)))) {
1498  if (prev) {
1499  prev->next = cur->next;
1500  if (cur == category->last)
1501  category->last = prev;
1502  } else {
1503  category->root = cur->next;
1504  if (cur == category->last)
1505  category->last = NULL;
1506  }
1507  ast_variable_destroy(cur);
1508  res = 0;
1509  } else
1510  prev = cur;
1511 
1512  cur = curn;
1513  ++num_item;
1514  }
1515  return res;
1516 }

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

◆ ast_variable_destroy()

static void ast_variable_destroy ( struct ast_variable doomed)
static

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

810 {
811  return ast_variable_find_in_list(category->root, variable);
812 }
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:904

References ast_variable_find_in_list(), and ast_category::root.

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

◆ ast_variable_find_in_list()

const char* ast_variable_find_in_list ( const struct ast_variable list,
const char *  variable 
)

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

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

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

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

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

905 {
906  const struct ast_variable *v;
907 
908  for (v = list; v; v = v->next) {
909  if (!strcasecmp(variable, v->name)) {
910  return v->value;
911  }
912  }
913  return NULL;
914 }

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(), and load_realtime_musiconhold().

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

917 {
918  const struct ast_variable *v;
919  const char *found = NULL;
920 
921  for (v = list; v; v = v->next) {
922  if (!strcasecmp(variable, v->name)) {
923  found = v->value;
924  }
925  }
926  return found;
927 }

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

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

◆ ast_variable_find_variable_in_list()

const struct ast_variable* ast_variable_find_variable_in_list ( const struct ast_variable list,
const char *  variable_name 
)

Gets a variable from a variable list by name.

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

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

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

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

815 {
816  const struct ast_variable *v;
817 
818  for (v = list; v; v = v->next) {
819  if (!strcasecmp(variable_name, v->name)) {
820  return v;
821  }
822  }
823  return NULL;
824 }

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

Referenced by ast_variable_lists_match(), and realtime_sorcery_store().

◆ ast_variable_insert()

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

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

500 {
501  struct ast_variable *cur = category->root;
502  int lineno;
503  int insertline;
504 
505  if (!variable || sscanf(line, "%30d", &insertline) != 1) {
506  return;
507  }
508  if (!insertline) {
509  variable->next = category->root;
510  category->root = variable;
511  } else {
512  for (lineno = 1; lineno < insertline; lineno++) {
513  cur = cur->next;
514  if (!cur->next) {
515  break;
516  }
517  }
518  variable->next = cur->next;
519  cur->next = variable;
520  }
521 }

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

Referenced by AST_TEST_DEFINE().

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

647 {
648  struct ast_variable *curr;
649  ast_assert(head != NULL);
650 
651  if (!*head) {
652  *head = newvar;
653  } else {
654  if (search_hint == NULL) {
655  search_hint = *head;
656  }
657  for (curr = search_hint; curr->next; curr = curr->next);
658  curr->next = newvar;
659  }
660 
661  for (curr = newvar; curr->next; curr = curr->next);
662 
663  return curr;
664 }
#define ast_assert(a)
Definition: utils.h:734

References ast_assert, ast_variable::next, and NULL.

Referenced by ast_sorcery_objectset_create2(), and AST_TEST_DEFINE().

◆ ast_variable_list_from_string()

struct ast_variable* ast_variable_list_from_string ( const char *  input,
const char *  item_separator,
const char *  name_value_separator 
)

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

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

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

727 {
728  char item_sep;
729  char nv_sep;
730  struct ast_variable *new_list = NULL;
731  struct ast_variable *new_var = NULL;
732  char *item_string;
733  char *item;
734  char *item_name;
735  char *item_value;
736 
737  if (ast_strlen_zero(input)) {
738  return NULL;
739  }
740 
741  item_sep = ast_strlen_zero(item_separator) ? ',' : item_separator[0];
742  nv_sep = ast_strlen_zero(name_value_separator) ? '=' : name_value_separator[0];
743  item_string = ast_strip(ast_strdupa(input));
744 
745  while ((item = ast_strsep(&item_string, item_sep, AST_STRSEP_ALL))) {
746  item_name = ast_strsep(&item, nv_sep, AST_STRSEP_ALL);
747  item_value = ast_strsep(&item, nv_sep, AST_STRSEP_ALL);
748  new_var = ast_variable_new(item_name, item_value, "");
749  if (!new_var) {
750  ast_variables_destroy(new_list);
751  return NULL;
752  }
753  ast_variable_list_append(&new_list, new_var);
754  }
755  return new_list;
756 }
static int input(yyscan_t yyscanner)
Definition: ast_expr2f.c:1584
#define ast_variable_list_append(head, new_var)
@ AST_STRSEP_ALL
Definition: strings.h:258
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:223
char * ast_strsep(char **s, const char sep, uint32_t flags)
Act like strsep but ignore separators inside quotes.
Definition: main/utils.c:1802
static struct aco_type item
Definition: test_config.c:1463

References ast_strdupa, ast_strip(), ast_strlen_zero(), ast_strsep(), AST_STRSEP_ALL, ast_variable_list_append, ast_variable_new, ast_variables_destroy(), input(), item, and NULL.

Referenced by AST_TEST_DEFINE().

◆ ast_variable_list_join()

struct ast_str* ast_variable_list_join ( const struct ast_variable head,
const char *  item_separator,
const char *  name_value_separator,
const char *  quote_char,
struct ast_str **  str 
)

Join an ast_variable list with specified separators and quoted values.

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

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

701 {
702  struct ast_variable *var = (struct ast_variable *)head;
703  struct ast_str *local_str = NULL;
704 
705  if (str == NULL || *str == NULL) {
706  local_str = ast_str_create(AST_MAX_USER_FIELD);
707  if (!local_str) {
708  return NULL;
709  }
710  } else {
711  local_str = *str;
712  }
713 
714  for (; var; var = var->next) {
715  ast_str_append(&local_str, 0, "%s%s%s%s%s%s", var->name, name_value_separator, S_OR(quote_char, ""),
716  var->value, S_OR(quote_char, ""), var->next ? item_separator : "");
717  }
718 
719  if (str != NULL) {
720  *str = local_str;
721  }
722  return local_str;
723 }
#define AST_MAX_USER_FIELD
Definition: channel.h:174
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:80

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

Referenced by AST_TEST_DEFINE().

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

667 {
668  struct ast_variable *v, **prev = head;
669 
670  for (v = *head; v; prev = &v->next, v = v->next) {
671  if (!strcmp(v->name, replacement->name)) {
672  replacement->next = v->next;
673  *prev = replacement;
674  ast_free(v);
675  return 0;
676  }
677  }
678 
679  return -1;
680 }

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

◆ ast_variable_list_replace_variable()

int ast_variable_list_replace_variable ( struct ast_variable **  head,
struct ast_variable oldvar,
struct ast_variable newvar 
)

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

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

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

684 {
685  struct ast_variable *v, **prev = head;
686 
687  for (v = *head; v; prev = &v->next, v = v->next) {
688  if (v == old) {
689  new->next = v->next;
690  *prev = new;
691  ast_free(v);
692  return 0;
693  }
694  }
695 
696  return -1;
697 }

References ast_free, and ast_variable::next.

Referenced by AST_TEST_DEFINE().

◆ ast_variable_list_sort()

struct ast_variable* ast_variable_list_sort ( struct ast_variable head)

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

Parameters
headThe variable list head
Returns
The new list head

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

621 {
622  struct ast_variable *p, *q;
623  struct ast_variable top;
624  int changed = 1;
625  memset(&top, 0, sizeof(top));
626  top.next = start;
627  if (start != NULL && start->next != NULL) {
628  while (changed) {
629  changed = 0;
630  q = &top;
631  p = top.next;
632  while (p->next != NULL) {
633  if (p->next != NULL && strcmp(p->name, p->next->name) > 0) {
634  q->next = variable_list_switch(p, p->next);
635  changed = 1;
636  }
637  q = p;
638  if (p->next != NULL)
639  p = p->next;
640  }
641  }
642  }
643  return top.next;
644 }
static struct ast_variable * variable_list_switch(struct ast_variable *l1, struct ast_variable *l2)
Definition: main/config.c:613

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

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

◆ ast_variable_lists_match()

int ast_variable_lists_match ( const struct ast_variable left,
const struct ast_variable right,
int  exact_match 
)

Tests 2 variable lists to see if they match.

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

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

Return values
1matches
0doesn't match

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

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

847 {
848  const struct ast_variable *field;
849  int right_count = 0;
850  int left_count = 0;
851 
852  if (left == right) {
853  return 1;
854  }
855 
856  if (!(left && right)) {
857  return 0;
858  }
859 
860  for (field = right; field; field = field->next) {
861  char *space = strrchr(field->name, ' ');
862  const struct ast_variable *old;
863  char * name = (char *)field->name;
864 
865  if (space) {
866  name = ast_strdup(field->name);
867  if (!name) {
868  return 0;
869  }
870  name[space - field->name] = '\0';
871  }
872 
874  if (name != field->name) {
875  ast_free(name);
876  }
877 
878  if (exact_match) {
879  if (!old || strcmp(old->value, field->value)) {
880  return 0;
881  }
882  } else {
883  if (!ast_variables_match(old, field)) {
884  return 0;
885  }
886  }
887 
888  right_count++;
889  }
890 
891  if (exact_match) {
892  for (field = left; field; field = field->next) {
893  left_count++;
894  }
895 
896  if (right_count != left_count) {
897  return 0;
898  }
899  }
900 
901  return 1;
902 }
if(!yyg->yy_init)
Definition: ast_expr2f.c:868
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:826
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:814

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

◆ ast_variable_move()

static void ast_variable_move ( struct ast_variable dst_var,
struct ast_variable src_var 
)
static

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

323 {
324  dst_var->lineno = src_var->lineno;
325  dst_var->object = src_var->object;
326  dst_var->blanklines = src_var->blanklines;
327  dst_var->precomments = src_var->precomments;
328  src_var->precomments = NULL;
329  dst_var->sameline = src_var->sameline;
330  src_var->sameline = NULL;
331  dst_var->trailing = src_var->trailing;
332  src_var->trailing = NULL;
333 }

References ast_variable::blanklines, ast_variable::lineno, NULL, ast_variable::object, ast_variable::precomments, ast_variable::sameline, and ast_variable::trailing.

Referenced by ast_include_rename(), and ast_variable_update().

◆ ast_variable_retrieve()

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

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

769 {
770  struct ast_variable *v;
771 
772  if (category) {
773  for (v = ast_variable_browse(config, category); v; v = v->next) {
774  if (!strcasecmp(variable, v->name)) {
775  return v->value;
776  }
777  }
778  } else {
779  struct ast_category *cat;
780 
781  for (cat = config->root; cat; cat = cat->next) {
782  for (v = cat->root; v; v = v->next) {
783  if (!strcasecmp(variable, v->name)) {
784  return v->value;
785  }
786  }
787  }
788  }
789 
790  return NULL;
791 }
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Definition: main/config.c:600

References ast_variable_browse(), config, ast_variable::name, ast_variable::next, ast_category::next, NULL, ast_category::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(), 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_module(), load_mysql_config(), load_realtime_musiconhold(), load_realtime_queues(), load_realtime_rules(), load_tech_calendars(), load_users(), loader_config_init(), make_email_file(), mbl_load_adapter(), mbl_load_device(), message_range_and_existence_check(), named_acl_find_realtime(), notify_new_message(), odbc_load_module(), 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_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_change_password(), vm_forwardoptions(), vm_msg_forward(), and vm_msg_snapshot_create().

◆ ast_variable_retrieve_filtered()

const char* ast_variable_retrieve_filtered ( struct ast_config config,
const char *  category,
const char *  variable,
const char *  filter 
)

Gets a variable by context and variable names.

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

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

795 {
796  struct ast_category *cat = NULL;
797  const char *value;
798 
799  while ((cat = ast_category_browse_filtered(config, category, cat, filter))) {
800  value = ast_variable_find(cat, variable);
801  if (value) {
802  return value;
803  }
804  }
805 
806  return NULL;
807 }
struct ast_category * ast_category_browse_filtered(struct ast_config *config, const char *category_name, struct ast_category *prev, const char *filter)
Browse categories with filters.
Definition: main/config.c:1409
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:809

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

◆ ast_variable_update()

int ast_variable_update ( struct ast_category category,
const char *  variable,
const char *  value,
const char *  match,
unsigned int  object 
)

Update variable value within a config.

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

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

1520 {
1521  struct ast_variable *cur, *prev=NULL, *newer=NULL;
1522 
1523  for (cur = category->root; cur; prev = cur, cur = cur->next) {
1524  if (strcasecmp(cur->name, variable) ||
1525  (!ast_strlen_zero(match) && strcasecmp(cur->value, match)))
1526  continue;
1527 
1528  if (!(newer = ast_variable_new(variable, value, cur->file)))
1529  return -1;
1530 
1531  ast_variable_move(newer, cur);
1532  newer->object = newer->object || object;
1533 
1534  /* Replace the old node in the list with the new node. */
1535  newer->next = cur->next;
1536  if (prev)
1537  prev->next = newer;
1538  else
1539  category->root = newer;
1540  if (category->last == cur)
1541  category->last = newer;
1542 
1543  ast_variable_destroy(cur);
1544 
1545  return 0;
1546  }
1547 
1548  /* Could not find variable to update */
1549  return -1;
1550 }

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

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

◆ ast_variables_destroy()

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

590 {
591  struct ast_variable *vn;
592 
593  while (var) {
594  vn = var;
595  var = var->next;
597  }
598 }

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

Referenced by __init_manager(), aco_set_defaults(), action_messagesend(), action_originate(), add_message_id(), aeap_cli_show(), announce_to_dial(), ast_aeap_client_configs_get(), 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_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_variable_list_from_string(), ast_variables_dup(), auth_http_callback(), build_gateway(), build_peer(), calendar_destructor(), can_reuse_registration(), check_expiration_thread(), 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_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(), process_dahdi(), publication_resource_destroy(), pvt_destructor(), queue_function_queuegetchannel(), queue_function_queuewaitingcount(), realtime_arguments_to_fields(), realtime_arguments_to_fields2(), realtime_canmatch(), realtime_common(), realtime_exec(), realtime_exists(), realtime_ldap_base(), realtime_ldap_base_ap(), realtime_ldap_result_to_vars(), realtime_matchmore(), realtime_odbc(), realtime_peer(), realtime_peer_by_addr(), realtime_peer_by_name(), realtime_peer_get_sippeer_helper(), realtime_user(), realtimefield_read(), 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_is_criteria_met(), sorcery_memory_cache_fields_cmp(), sorcery_memory_cached_object_destructor(), sorcery_memory_fields_cmp(), sorcery_object_destructor(), sorcery_realtime_create(), sorcery_realtime_filter_objectset(), sorcery_realtime_retrieve_fields(), sorcery_realtime_retrieve_id(), sorcery_realtime_retrieve_multiple(), sorcery_realtime_retrieve_prefix(), sorcery_realtime_retrieve_regex(), sorcery_realtime_update(), speech_aeap_engine_create(), stir_shaken_cli_show(), table_configs_free(), test_sorcery_object_destroy(), test_sorcery_transform(), transport_apply(), and user_destructor().

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

544 {
545  struct ast_variable *cloned;
546  struct ast_variable *tmp;
547 
548  if (!(cloned = ast_variable_new(var->name, var->value, var->file))) {
549  return NULL;
550  }
551 
552  tmp = cloned;
553 
554  while ((var = var->next)) {
555  if (!(tmp->next = ast_variable_new(var->name, var->value, var->file))) {
556  ast_variables_destroy(cloned);
557  return NULL;
558  }
559  tmp = tmp->next;
560  }
561 
562  return cloned;
563 }

References ast_variable_new, ast_variables_destroy(), NULL, tmp(), and var.

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

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

827 {
828  char *op;
829 
830  if (left == right) {
831  return 1;
832  }
833 
834  if (!(left && right)) {
835  return 0;
836  }
837 
838  op = strrchr(right->name, ' ');
839  if (op) {
840  op++;
841  }
842 
843  return ast_strings_match(left->value, op ? ast_strdupa(op) : NULL, right->value);
844 }
int ast_strings_match(const char *left, const char *op, const char *right)
Compares 2 strings using realtime-style operators.
Definition: strings.c:248

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

Referenced by ast_variable_lists_match().

◆ ast_variables_reverse()

struct ast_variable* ast_variables_reverse ( struct ast_variable var)

Reverse a variable list.

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

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

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

References ast_variable::next, NULL, and var.

Referenced by astman_get_variables_order().

◆ category_get_sep()

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 
)
static

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

1076 {
1077  struct ast_category *cat;
1078 
1079  if (pointer_match_possible) {
1080  for (cat = config->root; cat; cat = cat->next) {
1081  if (cat->name == category_name && does_category_match(cat, category_name, filter, sep)) {
1082  return cat;
1083  }
1084  }
1085  }
1086 
1087  for (cat = config->root; cat; cat = cat->next) {
1088  if (does_category_match(cat, category_name, filter, sep)) {
1089  return cat;
1090  }
1091  }
1092 
1093  return NULL;
1094 }
static int does_category_match(struct ast_category *cat, const char *category_name, const char *match, char sep)
Returns true if ALL of the regex expressions and category name match. Both can be NULL (I....
Definition: main/config.c:955

References config, does_category_match(), filter(), ast_category::name, ast_category::next, and NULL.

Referenced by ast_category_get(), and process_text_line().

◆ CB_ADD()

static void CB_ADD ( struct ast_str **  cb,
const char *  str 
)
static

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

130 {
131  ast_str_append(cb, 0, "%s", str);
132 }

References ast_str_append(), and str.

Referenced by config_text_file_load().

◆ CB_ADD_LEN()

static void CB_ADD_LEN ( struct ast_str **  cb,
const char *  str,
int  len 
)
static

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

135 {
136  char *s = ast_alloca(len + 1);
137 
138  memcpy(s, str, len);
139  s[len] = '\0';
140  ast_str_append(cb, 0, "%s", s);
141 }
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:288
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)

References ast_alloca, ast_str_append(), len(), and str.

Referenced by config_text_file_load().

◆ CB_RESET()

static void CB_RESET ( struct ast_str cb,
struct ast_str llb 
)
static

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

144 {
145  if (cb) {
146  ast_str_reset(cb);
147  }
148  if (llb) {
149  ast_str_reset(llb);
150  }
151 }

References ast_str_reset().

Referenced by config_text_file_load(), and process_text_line().

◆ cfmstat_cmp()

static int cfmstat_cmp ( struct cache_file_mtime cfmtime,
struct stat *  statbuf 
)
static

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

1691 {
1692  struct cache_file_mtime cfm_buf;
1693 
1694  cfmstat_save(&cfm_buf, statbuf);
1695 
1696  return cfmtime->stat_size != cfm_buf.stat_size
1697  || cfmtime->stat_mtime != cfm_buf.stat_mtime
1698  || cfmtime->stat_mtime_nsec != cfm_buf.stat_mtime_nsec;
1699 }
static void cfmstat_save(struct cache_file_mtime *cfmtime, struct stat *statbuf)
Definition: main/config.c:1666
unsigned long stat_size
Definition: main/config.c:102
unsigned long stat_mtime_nsec
Definition: main/config.c:104

References cfmstat_save(), cache_file_mtime::stat_mtime, cache_file_mtime::stat_mtime_nsec, and cache_file_mtime::stat_size.

Referenced by config_text_file_load().

◆ cfmstat_save()

static void cfmstat_save ( struct cache_file_mtime cfmtime,
struct stat *  statbuf 
)
static

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

1667 {
1668  cfmtime->stat_size = statbuf->st_size;
1669 #if defined(HAVE_STRUCT_STAT_ST_MTIM)
1670  cfmtime->stat_mtime_nsec = statbuf->st_mtim.tv_nsec;
1671 #elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC)
1672  cfmtime->stat_mtime_nsec = statbuf->st_mtimensec;
1673 #elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC)
1674  cfmtime->stat_mtime_nsec = statbuf->st_mtimespec.tv_nsec;
1675 #else
1676  cfmtime->stat_mtime_nsec = 0;
1677 #endif
1678  cfmtime->stat_mtime = statbuf->st_mtime;
1679 }

References cache_file_mtime::stat_mtime, cache_file_mtime::stat_mtime_nsec, and cache_file_mtime::stat_size.

Referenced by cfmstat_cmp(), and config_text_file_load().

◆ cfmtime_new()

static struct cache_file_mtime* cfmtime_new ( const char *  filename,
const char *  who_asked 
)
static

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

1637 {
1638  struct cache_file_mtime *cfmtime;
1639  char *dst;
1640 
1641  cfmtime = ast_calloc(1,
1642  sizeof(*cfmtime) + strlen(filename) + 1 + strlen(who_asked) + 1);
1643  if (!cfmtime) {
1644  return NULL;
1645  }
1646  dst = cfmtime->filename; /* writable space starts here */
1647  strcpy(dst, filename); /* Safe */
1648  dst += strlen(dst) + 1;
1649  cfmtime->who_asked = strcpy(dst, who_asked); /* Safe */
1650 
1651  return cfmtime;
1652 }
const char * who_asked
Definition: main/config.c:109

References ast_calloc, cache_file_mtime::filename, NULL, and cache_file_mtime::who_asked.

Referenced by config_cache_attribute(), and config_text_file_load().

◆ clear_config_maps()

static void clear_config_maps ( void  )
static

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

2923 {
2924  struct ast_config_map *map;
2925 
2926  while (config_maps) {
2927  map = config_maps;
2929  ast_free(map);
2930  }
2931 }

References ast_free, config_maps, and ast_config_map::next.

Referenced by config_shutdown(), and reload_module().

◆ config_cache_attribute()

static void config_cache_attribute ( const char *  configfile,
enum config_cache_attribute_enum  attrtype,
const char *  filename,
const char *  who_asked 
)
static

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

1757 {
1758  struct cache_file_mtime *cfmtime;
1759  struct cache_file_include *cfinclude;
1760 
1761  /* Find our cached entry for this configuration file */
1763  AST_LIST_TRAVERSE(&cfmtime_head, cfmtime, list) {
1764  if (!strcmp(cfmtime->filename, configfile) && !strcmp(cfmtime->who_asked, who_asked))
1765  break;
1766  }
1767  if (!cfmtime) {
1768  cfmtime = cfmtime_new(configfile, who_asked);
1769  if (!cfmtime) {
1771  return;
1772  }
1773  /* Note that the file mtime is initialized to 0, i.e. 1970 */
1774  AST_LIST_INSERT_SORTALPHA(&cfmtime_head, cfmtime, list, filename);
1775  }
1776 
1777  switch (attrtype) {
1778  case ATTRIBUTE_INCLUDE:
1779  AST_LIST_TRAVERSE(&cfmtime->includes, cfinclude, list) {
1780  if (!strcmp(cfinclude->include, filename)) {
1782  return;
1783  }
1784  }
1785  cfinclude = ast_calloc(1, sizeof(*cfinclude) + strlen(filename) + 1);
1786  if (!cfinclude) {
1788  return;
1789  }
1790  strcpy(cfinclude->include, filename); /* Safe */
1791  AST_LIST_INSERT_TAIL(&cfmtime->includes, cfinclude, list);
1792  break;
1793  case ATTRIBUTE_EXEC:
1794  cfmtime->has_exec = 1;
1795  break;
1796  }
1798 }
#define AST_LIST_INSERT_SORTALPHA(head, elm, field, sortfield)
Inserts a list entry into a alphabetically sorted list.
Definition: linkedlists.h:751
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:40
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:140
static struct cache_file_mtime * cfmtime_new(const char *filename, const char *who_asked)
Definition: main/config.c:1636
Hold the mtime for config files, so if we don't need to reread our config, don't.
Definition: main/config.c:91
struct cache_file_include::@365 list
struct cache_file_mtime::includes includes
unsigned int has_exec
Definition: main/config.c:100

References ast_calloc, AST_LIST_INSERT_SORTALPHA, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ATTRIBUTE_EXEC, ATTRIBUTE_INCLUDE, cfmtime_new(), cache_file_mtime::filename, cache_file_mtime::has_exec, cache_file_include::include, cache_file_mtime::includes, and cache_file_mtime::who_asked.

Referenced by process_text_line().

◆ config_cache_destroy_entry()

static void config_cache_destroy_entry ( struct cache_file_mtime cfmtime)
static

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

1727 {
1728  config_cache_flush_includes(cfmtime);
1729  ast_free(cfmtime);
1730 }
static void config_cache_flush_includes(struct cache_file_mtime *cfmtime)
Definition: main/config.c:1709

References ast_free, and config_cache_flush_includes().

Referenced by config_cache_remove(), and config_shutdown().

◆ config_cache_flush_includes()

static void config_cache_flush_includes ( struct cache_file_mtime cfmtime)
static

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

1710 {
1711  struct cache_file_include *cfinclude;
1712 
1713  while ((cfinclude = AST_LIST_REMOVE_HEAD(&cfmtime->includes, list))) {
1714  ast_free(cfinclude);
1715  }
1716 }

References ast_free, AST_LIST_REMOVE_HEAD, and cache_file_mtime::includes.

Referenced by config_cache_destroy_entry(), and config_text_file_load().

◆ config_cache_remove()

static void config_cache_remove ( const char *  filename,
const char *  who_asked 
)
static

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

1740 {
1741  struct cache_file_mtime *cfmtime;
1742 
1745  if (!strcmp(cfmtime->filename, filename)
1746  && !strcmp(cfmtime->who_asked, who_asked)) {
1748  config_cache_destroy_entry(cfmtime);
1749  break;
1750  }
1751  }
1754 }
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:615
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:529
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:557
static void config_cache_destroy_entry(struct cache_file_mtime *cfmtime)
Definition: main/config.c:1726
struct cache_file_mtime::@366 list

References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, config_cache_destroy_entry(), cache_file_mtime::filename, and cache_file_mtime::who_asked.

Referenced by config_text_file_load().

◆ config_hook_exec()

static void config_hook_exec ( const char *  filename,
const char *  module,
const struct ast_config cfg 
)
static

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

4183 {
4184  struct ao2_iterator it;
4185  struct cfg_hook *hook;
4186  if (!(cfg_hooks)) {
4187  return;
4188  }
4189  it = ao2_iterator_init(cfg_hooks, 0);
4190  while ((hook = ao2_iterator_next(&it))) {
4191  if (!strcasecmp(hook->filename, filename) &&
4192  !strcasecmp(hook->module, module)) {
4193  struct ast_config *copy = ast_config_copy(cfg);
4194  hook->hook_cb(copy);
4195  }
4196  ao2_ref(hook, -1);
4197  }
4198  ao2_iterator_destroy(&it);
4199 }
static int copy(char *infile, char *outfile)
Utility function to copy a file.
#define ao2_iterator_next(iter)
Definition: astobj2.h:1911
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
struct ast_config * ast_config_copy(const struct ast_config *old)
Copies the contents of one ast_config into another.
Definition: main/config.c:3145
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1821

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_config_copy(), cfg_hooks, copy(), cfg_hook::filename, cfg_hook::hook_cb, and cfg_hook::module.

Referenced by ast_config_internal_load(), and ast_config_text_file_save2().

◆ config_shutdown()

static void config_shutdown ( void  )
static

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

4118 {
4119  struct cache_file_mtime *cfmtime;
4120 
4122  while ((cfmtime = AST_LIST_REMOVE_HEAD(&cfmtime_head, list))) {
4123  config_cache_destroy_entry(cfmtime);
4124  }
4126 
4128 
4130 
4132  cfg_hooks = NULL;
4133 }
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
static struct ast_cli_entry cli_config[]
Definition: main/config.c:4111
static void clear_config_maps(void)
Definition: main/config.c:2922
#define ARRAY_LEN(a)
Definition: utils.h:661

References ao2_cleanup, ARRAY_LEN, ast_cli_unregister_multiple(), AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, cfg_hooks, clear_config_maps(), cli_config, config_cache_destroy_entry(), and NULL.

Referenced by register_config_cli().

◆ config_text_file_load()

static struct ast_config* config_text_file_load ( const char *  database,
const char *  table,
const char *  filename,
struct ast_config cfg,
struct ast_flags  flags,
const char *  suggested_include_file,
const char *  who_asked 
)
static

Growable string buffer

< this will be a comment collector.

< A buffer for stuff behind the ;

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

2109 {
2110  char fn[256];
2111 #if defined(LOW_MEMORY)
2112  char buf[512];
2113 #else
2114  char buf[8192];
2115 #endif
2116  char *new_buf, *comment_p, *process_buf;
2117  FILE *f;
2118  int lineno=0;
2119  int comment = 0, nest[MAX_NESTED_COMMENTS];
2120  struct ast_category *cat = NULL;
2121  int count = 0;
2122  struct stat statbuf;
2123  struct cache_file_mtime *cfmtime = NULL;
2124  struct cache_file_include *cfinclude;
2125  struct ast_variable *last_var = NULL;
2126  struct ast_category *last_cat = NULL;
2127  /*! Growable string buffer */
2128  struct ast_str *comment_buffer = NULL; /*!< this will be a comment collector.*/
2129  struct ast_str *lline_buffer = NULL; /*!< A buffer for stuff behind the ; */
2130  int glob_ret;
2131  glob_t globbuf;
2132 
2133  if (cfg) {
2135  }
2136 
2137  if (filename[0] == '/') {
2138  ast_copy_string(fn, filename, sizeof(fn));
2139  } else {