Wed Jan 8 2020 09:50:10

Asterisk developer's documentation


config.c File Reference

Configuration File Parser. More...

#include "asterisk.h"
#include "asterisk/paths.h"
#include "asterisk/network.h"
#include <time.h>
#include <sys/stat.h>
#include <math.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"

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  cfmtime_head
 
struct  inclfile
 
struct  cache_file_mtime::includes
 
struct  ast_category::template_instance_list
 

Macros

#define AST_INCLUDE_GLOB   1
 
#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
 

Enumerations

enum  config_cache_attribute_enum { ATTRIBUTE_INCLUDE = 0, ATTRIBUTE_EXEC = 1 }
 

Functions

static void __init_appendbuf (void)
 
static struct ast_commentALLOC_COMMENT (struct ast_str *buffer)
 
static int append_mapping (const char *name, const char *driver, const char *database, const char *table, int priority)
 
void ast_category_append (struct ast_config *config, struct ast_category *category)
 
char * ast_category_browse (struct ast_config *config, const char *prev)
 Goes through categories. More...
 
int ast_category_delete (struct ast_config *cfg, const char *category)
 
void ast_category_destroy (struct ast_category *cat)
 
struct ast_variableast_category_detach_variables (struct ast_category *cat)
 
int ast_category_empty (struct ast_config *cfg, const char *category)
 Removes and destroys all variables within a category. More...
 
int ast_category_exist (const struct ast_config *config, const char *category_name)
 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)
 Retrieve a category if it exists. More...
 
int ast_category_insert (struct ast_config *config, struct ast_category *cat, const char *match)
 Inserts new category. More...
 
struct ast_categoryast_category_new (const char *name, const char *in_file, int lineno)
 Create a category structure. 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)
 
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...
 
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...
 
int ast_config_text_file_save (const char *configfile, const struct ast_config *cfg, const char *generator)
 
int ast_destroy_realtime (const char *family, const char *keyfield, const char *lookup,...)
 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,...)
 Retrieve realtime configuration. More...
 
struct ast_variableast_load_realtime_all (const char *family,...)
 
static struct ast_variableast_load_realtime_helper (const char *family, va_list ap)
 
struct ast_configast_load_realtime_multientry (const char *family,...)
 Retrieve realtime configuration. More...
 
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...
 
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_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_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_update_realtime (const char *family, const char *keyfield, const char *lookup,...)
 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)
 Goes through variables. More...
 
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)
 
void ast_variable_insert (struct ast_category *category, struct ast_variable *variable, const char *line)
 
static void ast_variable_move (struct ast_variable *dst_var, struct ast_variable *src_var)
 
struct ast_variableast_variable_new (const char *name, const char *value, const char *filename)
 
const char * ast_variable_retrieve (const struct ast_config *config, const char *category, const char *variable)
 Gets a variable. 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 *v)
 Free variable list. More...
 
struct ast_variableast_variables_dup (struct ast_variable *var)
 Duplicate variable list. More...
 
struct ast_variableast_variables_reverse (struct ast_variable *var)
 Reverse a variable list. More...
 
static struct ast_categorycategory_get (const struct ast_config *config, const char *category_name, int ignored)
 
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_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)
 
int config_text_file_save (const char *configfile, const struct ast_config *cfg, const char *generator)
 
static int count_linefeeds (char *str)
 
static int count_linefeeds_in_comments (struct ast_comment *x)
 
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 void inclfile_destroy (void *obj)
 
static void inherit_category (struct ast_category *new, const struct ast_category *base)
 
static int init_appendbuf (void *data)
 
static void insert_leading_blank_lines (FILE *fp, struct inclfile *fi, struct ast_comment *precomments, int lineno)
 
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_categorynext_available_category (struct ast_category *cat)
 
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...
 
int read_config_maps (void)
 Exposed re-initialization method for core process. More...
 
int register_config_cli (void)
 Exposed initialization method for core process. More...
 
static struct inclfileset_fn (char *fn, size_t fn_size, const char *file, const char *configfile, struct ao2_container *fileset)
 
static struct ast_variablevariable_clone (const struct ast_variable *old)
 

Variables

static struct ast_threadstorage appendbuf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_appendbuf , .custom_init = init_appendbuf , }
 
static struct cfmtime_head cfmtime_head = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 } , }
 
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 }
 
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 config.c.

Macro Definition Documentation

#define AST_INCLUDE_GLOB   1

Definition at line 44 of file config.c.

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

Definition at line 116 of file config.c.

Referenced by config_text_file_load().

#define COMMENT_END   "--;"

Definition at line 58 of file config.c.

#define COMMENT_META   ';'

Definition at line 59 of file config.c.

Referenced by config_text_file_load().

#define COMMENT_START   ";--"

Definition at line 57 of file config.c.

#define COMMENT_TAG   '-'

Definition at line 60 of file config.c.

Referenced by config_text_file_load().

#define MAX_INCLUDE_LEVEL   10

Definition at line 206 of file config.c.

Referenced by ast_config_new().

#define MAX_NESTED_COMMENTS   128

Definition at line 56 of file config.c.

Referenced by config_text_file_load().

#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 67 of file config.c.

Referenced by ast_variable_new().

Enumeration Type Documentation

Enumerator
ATTRIBUTE_INCLUDE 
ATTRIBUTE_EXEC 

Definition at line 1094 of file config.c.

1094  {
1095  ATTRIBUTE_INCLUDE = 0,
1096  ATTRIBUTE_EXEC = 1,
1097 };

Function Documentation

static void __init_appendbuf ( void  )
static

Definition at line 113 of file config.c.

119 {
static struct ast_comment* ALLOC_COMMENT ( struct ast_str buffer)
static

Definition at line 142 of file config.c.

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

Referenced by config_text_file_load(), and process_text_line().

143 {
144  struct ast_comment *x = NULL;
145  if (!buffer || !ast_str_strlen(buffer)) {
146  return NULL;
147  }
148  if ((x = ast_calloc(1, sizeof(*x) + ast_str_strlen(buffer) + 1))) {
149  strcpy(x->cmt, ast_str_buffer(buffer)); /* SAFE */
150  }
151  return x;
152 }
Structure to keep comments for rewriting configuration files.
Definition: config.c:73
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:497
char cmt[0]
Definition: config.c:76
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:471
#define ast_calloc(a, b)
Definition: astmm.h:82
static int append_mapping ( const char *  name,
const char *  driver,
const char *  database,
const char *  table,
int  priority 
)
static

Definition at line 2263 of file config.c.

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

Referenced by read_config_maps().

2264 {
2265  struct ast_config_map *map;
2266  char *dst;
2267  int length;
2268 
2269  length = sizeof(*map);
2270  length += strlen(name) + 1;
2271  length += strlen(driver) + 1;
2272  length += strlen(database) + 1;
2273  if (table)
2274  length += strlen(table) + 1;
2275 
2276  if (!(map = ast_calloc(1, length)))
2277  return -1;
2278 
2279  dst = map->stuff; /* writable space starts here */
2280  map->name = strcpy(dst, name);
2281  dst += strlen(dst) + 1;
2282  map->driver = strcpy(dst, driver);
2283  dst += strlen(dst) + 1;
2284  map->database = strcpy(dst, database);
2285  if (table) {
2286  dst += strlen(dst) + 1;
2287  map->table = strcpy(dst, table);
2288  }
2289  map->priority = priority;
2290  map->next = config_maps;
2291  config_maps = map;
2292 
2293  ast_verb(2, "Binding %s to %s/%s/%s\n", map->name, map->driver, map->database, map->table ? map->table : map->name);
2294 
2295  return 0;
2296 }
char stuff[0]
Definition: config.c:200
static int * map
Definition: misdn_config.c:434
const char * database
Definition: config.c:196
const char * table
Definition: config.c:198
#define ast_verb(level,...)
Definition: logger.h:243
static struct ast_config_map * config_maps
static char * table
Definition: cdr_odbc.c:50
int priority
Definition: config.c:190
const char * name
Definition: config.c:192
static const char name[]
const char * driver
Definition: config.c:194
#define ast_calloc(a, b)
Definition: astmm.h:82
struct ast_config_map * next
Definition: config.c:189
void ast_category_append ( struct ast_config config,
struct ast_category category 
)

Definition at line 719 of file config.c.

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

Referenced by add_cfg_entry(), add_rt_multi_cfg_entry(), config_curl(), config_ldap(), config_odbc(), config_pgsql(), handle_updates(), process_text_line(), realtime_directory(), realtime_multi_curl(), realtime_multi_ldap(), realtime_multi_odbc(), realtime_multi_pgsql(), and write_password_to_file().

720 {
721  if (config->last)
722  config->last->next = category;
723  else
724  config->root = category;
725  category->include_level = config->include_level;
726  config->last = category;
727  config->current = category;
728 }
struct ast_category * current
Definition: config.c:241
int include_level
Definition: config.c:217
int include_level
Definition: config.c:243
struct ast_category * next
Definition: config.c:233
struct ast_category * last
Definition: config.c:240
struct ast_category * root
Definition: config.c:238
char* ast_category_browse ( struct ast_config config,
const char *  prev 
)

Goes through categories.

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

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 on success
NULLon failure/no-more-categories

Definition at line 810 of file config.c.

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

Referenced by __init_manager(), __queues_show(), action_getconfig(), action_getconfigjson(), action_listcategories(), actual_load_config(), aji_load_config(), ast_cli_perms_init(), complete_sipnotify(), conf_exec(), config_load(), find_queue_by_name_rt(), find_realtime(), get_insecure_variable_from_config(), get_insecure_variable_from_sipregs(), gtalk_load_config(), iax_provision_reload(), jingle_load_config(), load_config(), load_indications(), load_module(), load_moh_classes(), load_odbc_config(), load_pktccops_config(), load_tech_calendars(), misdn_cfg_init(), osp_load(), parse_config(), pbx_load_config(), pbx_load_users(), process_config(), queues_data_provider_get(), read_agent_config(), realtime_directory(), realtime_switch_common(), reload(), reload_config(), reload_followme(), reload_queue_rules(), reload_queues(), search_directory(), search_directory_sub(), set_config(), setup_dahdi_int(), show_users_realtime(), sla_load_config(), update_realtime_members(), and vm_change_password().

811 {
812  struct ast_category *cat;
813 
814  if (!prev) {
815  /* First time browse. */
816  cat = config->root;
817  } else if (config->last_browse && (config->last_browse->name == prev)) {
818  /* Simple last browse found. */
819  cat = config->last_browse->next;
820  } else {
821  /*
822  * Config changed since last browse.
823  *
824  * First try cheap last browse search. (Rebrowsing a different
825  * previous category?)
826  */
827  for (cat = config->root; cat; cat = cat->next) {
828  if (cat->name == prev) {
829  /* Found it. */
830  cat = cat->next;
831  break;
832  }
833  }
834  if (!cat) {
835  /*
836  * Have to do it the hard way. (Last category was deleted and
837  * re-added?)
838  */
839  for (cat = config->root; cat; cat = cat->next) {
840  if (!strcasecmp(cat->name, prev)) {
841  /* Found it. */
842  cat = cat->next;
843  break;
844  }
845  }
846  }
847  }
848 
849  if (cat)
850  cat = next_available_category(cat);
851 
852  config->last_browse = cat;
853  return (cat) ? cat->name : NULL;
854 }
struct ast_category * next
Definition: config.c:233
char name[80]
Definition: config.c:215
struct ast_category * last_browse
Definition: config.c:242
static struct ast_category * next_available_category(struct ast_category *cat)
Definition: config.c:788
struct ast_category * root
Definition: config.c:238
int ast_category_delete ( struct ast_config cfg,
const char *  category 
)

Definition at line 976 of file config.c.

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

Referenced by handle_updates().

977 {
978  struct ast_category *prev=NULL, *cat;
979 
980  cat = cfg->root;
981  while (cat) {
982  if (cat->name == category) {
983  if (prev) {
984  prev->next = cat->next;
985  if (cat == cfg->last)
986  cfg->last = prev;
987  } else {
988  cfg->root = cat->next;
989  if (cat == cfg->last)
990  cfg->last = NULL;
991  }
993  return 0;
994  }
995  prev = cat;
996  cat = cat->next;
997  }
998 
999  prev = NULL;
1000  cat = cfg->root;
1001  while (cat) {
1002  if (!strcasecmp(cat->name, category)) {
1003  if (prev) {
1004  prev->next = cat->next;
1005  if (cat == cfg->last)
1006  cfg->last = prev;
1007  } else {
1008  cfg->root = cat->next;
1009  if (cat == cfg->last)
1010  cfg->last = NULL;
1011  }
1012  ast_category_destroy(cat);
1013  return 0;
1014  }
1015  prev = cat;
1016  cat = cat->next;
1017  }
1018  return -1;
1019 }
struct ast_category * next
Definition: config.c:233
void ast_category_destroy(struct ast_category *cat)
Definition: config.c:762
struct ast_category * last
Definition: config.c:240
struct ast_category * root
Definition: config.c:238
void ast_category_destroy ( struct ast_category cat)

Definition at line 762 of file config.c.

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

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

763 {
765  cat->root = NULL;
766  cat->last = NULL;
771  ast_free(cat->file);
772  ast_free(cat);
773 }
static void ast_comment_destroy(struct ast_comment **comment)
Definition: config.c:520
struct ast_variable * last
Definition: config.c:231
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: config.c:586
struct ast_comment * trailing
Definition: config.c:227
struct ast_variable * root
Definition: config.c:229
static void ast_destroy_template_list(struct ast_category *cat)
Definition: config.c:754
struct ast_comment * sameline
Definition: config.c:226
#define ast_free(a)
Definition: astmm.h:97
struct ast_comment * precomments
Definition: config.c:225
char * file
The file name from whence this declaration was read.
Definition: config.c:222
struct ast_variable* ast_category_detach_variables ( struct ast_category cat)

Definition at line 856 of file config.c.

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

Referenced by realtime_switch_common().

857 {
858  struct ast_variable *v;
859 
860  v = cat->root;
861  cat->root = NULL;
862  cat->last = NULL;
863 
864  return v;
865 }
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
struct ast_variable * last
Definition: config.c:231
struct ast_variable * root
Definition: config.c:229
int ast_category_empty ( struct ast_config cfg,
const char *  category 
)

Removes and destroys all variables within a category.

Return values
0if the category was found and emptied
-1if the category was not found

Definition at line 1021 of file config.c.

References ast_variables_destroy(), ast_category::last, ast_category::name, ast_category::next, ast_category::root, and ast_config::root.

Referenced by handle_updates().

1022 {
1023  struct ast_category *cat;
1024 
1025  for (cat = cfg->root; cat; cat = cat->next) {
1026  if (strcasecmp(cat->name, category))
1027  continue;
1029  cat->root = NULL;
1030  cat->last = NULL;
1031  return 0;
1032  }
1033 
1034  return -1;
1035 }
struct ast_variable * last
Definition: config.c:231
struct ast_category * next
Definition: config.c:233
char name[80]
Definition: config.c:215
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: config.c:586
struct ast_variable * root
Definition: config.c:229
struct ast_category * root
Definition: config.c:238
int ast_category_exist ( const struct ast_config config,
const char *  category_name 
)

Check for category duplicates.

Parameters
configwhich config to use
category_namename of the category you're looking for

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

Returns
non-zero if found

Definition at line 714 of file config.c.

References ast_category_get().

715 {
716  return !!ast_category_get(config, category_name);
717 }
struct ast_category * ast_category_get(const struct ast_config *config, const char *category_name)
Retrieve a category if it exists.
Definition: config.c:709
struct ast_variable* ast_category_first ( struct ast_category cat)

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

return the first var of a category

Definition at line 796 of file config.c.

References ast_category::root.

Referenced by process_text_line().

797 {
798  return (cat) ? cat->root : NULL;
799 }
struct ast_variable * root
Definition: config.c:229
struct ast_category* ast_category_get ( const struct ast_config config,
const char *  category_name 
)

Retrieve a category if it exists.

Parameters
configwhich config to use
category_namename of the category you're looking for

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 709 of file config.c.

References category_get().

Referenced by ast_category_exist(), ast_category_root(), ast_variable_browse(), handle_updates(), realtime_directory(), realtime_switch_common(), vm_change_password(), and vm_forwardoptions().

710 {
711  return category_get(config, category_name, 0);
712 }
static struct ast_category * category_get(const struct ast_config *config, const char *category_name, int ignored)
Definition: config.c:691
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 NULL parameters or match category was not found

Definition at line 730 of file config.c.

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

Referenced by handle_updates().

731 {
732  struct ast_category *cur_category;
733 
734  if (!config || !cat || !match) {
735  return -1;
736  }
737  if (!strcasecmp(config->root->name, match)) {
738  cat->next = config->root;
739  config->root = cat;
740  return 0;
741  }
742  for (cur_category = config->root; cur_category && cur_category->next;
743  cur_category = cur_category->next) {
744  if (!strcasecmp(cur_category->next->name, match)) {
745  cat->next = cur_category->next;
746  cur_category->next = cat;
747  return 0;
748  }
749  }
750 
751  return -1;
752 }
struct ast_category * next
Definition: config.c:233
char name[80]
Definition: config.c:215
struct ast_category * root
Definition: config.c:238
static int match(struct sockaddr_in *sin, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Definition: chan_iax2.c:2069
struct ast_category* ast_category_new ( const char *  name,
const char *  in_file,
int  lineno 
)

Create a category structure.

Definition at line 673 of file config.c.

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

Referenced by add_cfg_entry(), add_rt_multi_cfg_entry(), config_curl(), config_ldap(), config_odbc(), config_pgsql(), handle_updates(), process_text_line(), realtime_directory(), realtime_multi_curl(), realtime_multi_ldap(), realtime_multi_odbc(), realtime_multi_pgsql(), and write_password_to_file().

674 {
675  struct ast_category *category;
676 
677  category = ast_calloc(1, sizeof(*category));
678  if (!category) {
679  return NULL;
680  }
681  category->file = ast_strdup(in_file);
682  if (!category->file) {
683  ast_category_destroy(category);
684  return NULL;
685  }
686  ast_copy_string(category->name, name, sizeof(category->name));
687  category->lineno = lineno; /* if you don't know the lineno, set it to 999999 or something real big */
688  return category;
689 }
#define ast_strdup(a)
Definition: astmm.h:109
char name[80]
Definition: config.c:215
int lineno
Definition: config.c:223
void ast_category_destroy(struct ast_category *cat)
Definition: config.c:762
static const char name[]
#define ast_calloc(a, b)
Definition: astmm.h:82
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
char * file
The file name from whence this declaration was read.
Definition: config.c:222
void ast_category_rename ( struct ast_category cat,
const char *  name 
)

Definition at line 867 of file config.c.

References ast_copy_string(), and ast_category::name.

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

868 {
869  ast_copy_string(cat->name, name, sizeof(cat->name));
870 }
char name[80]
Definition: config.c:215
static const char name[]
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
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 801 of file config.c.

References ast_category_get(), and ast_category::root.

Referenced by get_insecure_variable_from_config(), and get_insecure_variable_from_sipregs().

802 {
803  struct ast_category *category = ast_category_get(config, cat);
804 
805  if (category)
806  return category->root;
807  return NULL;
808 }
struct ast_category * ast_category_get(const struct ast_config *config, const char *category_name)
Retrieve a category if it exists.
Definition: config.c:709
struct ast_variable * root
Definition: config.c:229
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 2587 of file config.c.

References ast_realtime_enabled(), and find_engine().

Referenced by __queues_show(), _sip_show_peer(), _sip_show_peers(), 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(), local_ast_moh_start(), logger_queue_rt_start(), realtime_peer(), realtime_update_peer(), rename_file(), sip_poke_noanswer(), sip_show_settings(), and vm_delete().

2588 {
2589  struct ast_config_engine *eng;
2590  if (!ast_realtime_enabled()) {
2591  return 0; /* There are no engines at all so fail early */
2592  }
2593 
2594  eng = find_engine(family, 1, NULL, 0, NULL, 0);
2595  if (eng)
2596  return 1;
2597  return 0;
2598 }
int ast_realtime_enabled(void)
Check if there&#39;s any realtime engines loaded.
Definition: config.c:2601
Configuration engine structure, used to define realtime drivers.
Definition: config.h:121
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: config.c:2420
static void ast_comment_destroy ( struct ast_comment **  comment)
static

Definition at line 520 of file config.c.

References ast_free, and ast_comment::next.

Referenced by ast_category_destroy(), and ast_variable_destroy().

521 {
522  struct ast_comment *n, *p;
523 
524  for (p = *comment; p; p = n) {
525  n = p->next;
526  ast_free(p);
527  }
528 
529  *comment = NULL;
530 }
Structure to keep comments for rewriting configuration files.
Definition: config.c:73
struct ast_comment * next
Definition: config.c:74
#define ast_free(a)
Definition: astmm.h:97
void ast_config_destroy ( struct ast_config config)

Destroys a config.

Parameters
configpointer to config data structure

Free memory associated with a given config

Definition at line 1037 of file config.c.

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

Referenced by __ast_http_load(), __ast_http_post_load(), __ast_udptl_reload(), __init_manager(), __queues_show(), _dsp_init(), action_getconfig(), action_getconfigjson(), action_listcategories(), action_updateconfig(), adsi_load(), advanced_options(), aji_load_config(), ast_cli_perms_init(), ast_config_load2(), ast_load_realtime_multientry(), ast_plc_reload(), ast_readconfig(), ast_xmldoc_load_documentation(), conf_exec(), config_function_read(), config_load(), config_module(), directory_exec(), do_reload(), festival_exec(), find_conf(), find_realtime(), get_insecure_variable_from_sippeers(), get_insecure_variable_from_sipregs(), gtalk_load_config(), handle_cli_dialplan_save(), iax_provision_reload(), init_logger_chain(), initialize_cc_max_requests(), jingle_load_config(), load_config(), load_config_meetme(), load_indications(), load_module(), load_modules(), load_moh_classes(), load_odbc_config(), load_pktccops_config(), load_realtime_queue(), make_email_file(), misdn_cfg_init(), odbc_load_module(), osp_load(), parse_config(), pbx_load_config(), pbx_load_users(), play_message(), prep_email_sub_vars(), private_enum_init(), queues_data_provider_get(), read_agent_config(), read_config_maps(), read_password_from_file(), realtime_directory(), realtime_multi_handler(), realtime_multi_pgsql(), realtime_switch_common(), reload(), reload_config(), reload_followme(), reload_module(), reload_queue_rules(), reload_queues(), rtp_reload(), run_startup_commands(), set_config(), setup_dahdi_int(), show_users_realtime(), sla_load_config(), smdi_load(), tds_load_module(), unload_module(), update_realtime_members(), vm_change_password(), vm_forwardoptions(), and write_password_to_file().

1038 {
1039  struct ast_category *cat, *catn;
1040 
1041  if (!cfg)
1042  return;
1043 
1045 
1046  cat = cfg->root;
1047  while (cat) {
1048  catn = cat;
1049  cat = cat->next;
1050  ast_category_destroy(catn);
1051  }
1052  ast_free(cfg);
1053 }
struct ast_category * next
Definition: config.c:233
static void ast_includes_destroy(struct ast_config_include *incls)
Definition: config.c:775
void ast_category_destroy(struct ast_category *cat)
Definition: config.c:762
#define ast_free(a)
Definition: astmm.h:97
struct ast_category * root
Definition: config.c:238
struct ast_config_include * includes
Definition: config.c:245
int ast_config_engine_deregister ( struct ast_config_engine del)

Deregister config engine.

Return values
0Always

Definition at line 2397 of file config.c.

References ast_mutex_lock, ast_mutex_unlock, config_lock, last, and ast_config_engine::next.

Referenced by unload_module().

2398 {
2399  struct ast_config_engine *ptr, *last=NULL;
2400 
2402 
2403  for (ptr = config_engine_list; ptr; ptr=ptr->next) {
2404  if (ptr == del) {
2405  if (last)
2406  last->next = ptr->next;
2407  else
2408  config_engine_list = ptr->next;
2409  break;
2410  }
2411  last = ptr;
2412  }
2413 
2415 
2416  return 0;
2417 }
struct ast_config_engine * next
Definition: config.h:132
static ast_mutex_t config_lock
Definition: config.c:203
#define ast_mutex_lock(a)
Definition: lock.h:155
Configuration engine structure, used to define realtime drivers.
Definition: config.h:121
struct sla_ringing_trunk * last
Definition: app_meetme.c:965
static struct ast_config_engine * config_engine_list
Definition: config.c:204
#define ast_mutex_unlock(a)
Definition: lock.h:156
int ast_config_engine_register ( struct ast_config_engine newconfig)

Register config engine.

Return values
1Always

Definition at line 2378 of file config.c.

References ast_log(), ast_mutex_lock, ast_mutex_unlock, config_lock, LOG_NOTICE, and ast_config_engine::next.

Referenced by load_module().

2379 {
2380  struct ast_config_engine *ptr;
2381 
2383 
2384  if (!config_engine_list) {
2385  config_engine_list = new;
2386  } else {
2387  for (ptr = config_engine_list; ptr->next; ptr=ptr->next);
2388  ptr->next = new;
2389  }
2390 
2392  ast_log(LOG_NOTICE,"Registered Config Engine %s\n", new->name);
2393 
2394  return 1;
2395 }
struct ast_config_engine * next
Definition: config.h:132
static ast_mutex_t config_lock
Definition: config.c:203
#define ast_mutex_lock(a)
Definition: lock.h:155
Configuration engine structure, used to define realtime drivers.
Definition: config.h:121
static struct ast_config_engine * config_engine_list
Definition: config.c:204
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
#define ast_mutex_unlock(a)
Definition: lock.h:156
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 1055 of file config.c.

References ast_config::current.

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

1056 {
1057  return cfg->current;
1058 }
struct ast_category * current
Definition: config.c:241
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 2459 of file config.c.

References ast_log(), ast_test_flag, CONFIG_FLAG_NOREALTIME, 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, table, and text_file_engine.

Referenced by add_cfg_entry(), ast_config_load2(), config_curl(), config_ldap(), config_odbc(), config_pgsql(), process_text_line(), and read_config_maps().

2460 {
2461  char db[256];
2462  char table[256];
2463  struct ast_config_engine *loader = &text_file_engine;
2464  struct ast_config *result;
2465 
2466  /* The config file itself bumps include_level by 1 */
2467  if (cfg->max_include_level > 0 && cfg->include_level == cfg->max_include_level + 1) {
2468  ast_log(LOG_WARNING, "Maximum Include level (%d) exceeded\n", cfg->max_include_level);
2469  return NULL;
2470  }
2471 
2472  cfg->include_level++;
2473 
2475  struct ast_config_engine *eng;
2476 
2477  eng = find_engine(filename, 1, db, sizeof(db), table, sizeof(table));
2478 
2479 
2480  if (eng && eng->load_func) {
2481  loader = eng;
2482  } else {
2483  eng = find_engine("global", 1, db, sizeof(db), table, sizeof(table));
2484  if (eng && eng->load_func)
2485  loader = eng;
2486  }
2487  }
2488 
2489  result = loader->load_func(db, table, filename, cfg, flags, suggested_include_file, who_asked);
2490 
2491  if (result && result != CONFIG_STATUS_FILEINVALID && result != CONFIG_STATUS_FILEUNCHANGED)
2492  result->include_level--;
2493  else if (result != CONFIG_STATUS_FILEINVALID)
2494  cfg->include_level--;
2495 
2496  return result;
2497 }
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define LOG_WARNING
Definition: logger.h:144
int include_level
Definition: config.c:243
Configuration engine structure, used to define realtime drivers.
Definition: config.h:121
static char * table
Definition: cdr_odbc.c:50
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: config.c:2420
config_load_func * load_func
Definition: config.h:123
static struct ast_config_engine * config_engine_list
Definition: config.c:204
static struct ast_config_engine text_file_engine
Definition: config.c:2454
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static sqlite * db
Definition: cdr_sqlite.c:62
int max_include_level
Definition: config.c:244
#define CONFIG_STATUS_FILEINVALID
Definition: config.h:52
#define CONFIG_STATUS_FILEUNCHANGED
Definition: config.h:51
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 2499 of file config.c.

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

Referenced by __ast_http_load(), __ast_http_post_load(), __ast_udptl_reload(), __init_manager(), _dsp_init(), action_getconfig(), action_getconfigjson(), action_listcategories(), action_updateconfig(), ast_cli_perms_init(), ast_readconfig(), ast_xmldoc_load_documentation(), do_reload(), iax_provision_reload(), init_logger_chain(), initialize_cc_max_requests(), load_config(), load_indications(), load_modules(), misdn_cfg_init(), private_enum_init(), rtp_reload(), run_startup_commands(), and set_config().

2500 {
2501  struct ast_config *cfg;
2502  struct ast_config *result;
2503 
2504  cfg = ast_config_new();
2505  if (!cfg)
2506  return NULL;
2507 
2508  result = ast_config_internal_load(filename, cfg, flags, "", who_asked);
2509  if (!result || result == CONFIG_STATUS_FILEUNCHANGED || result == CONFIG_STATUS_FILEINVALID)
2510  ast_config_destroy(cfg);
2511 
2512  return result;
2513 }
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: config.c:1037
struct ast_config * ast_config_new(void)
Create a new base configuration structure.
Definition: config.c:888
#define CONFIG_STATUS_FILEINVALID
Definition: config.h:52
struct ast_config * ast_config_internal_load(const char *configfile, struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl_file, const char *who_asked)
Definition: config.c:2459
#define CONFIG_STATUS_FILEUNCHANGED
Definition: config.h:51
struct ast_config* ast_config_new ( void  )

Create a new base configuration structure.

Definition at line 888 of file config.c.

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

Referenced by ast_config_load2(), load_realtime_queue(), read_config_maps(), realtime_multi_curl(), realtime_multi_handler(), realtime_multi_ldap(), realtime_multi_odbc(), realtime_multi_pgsql(), setup_dahdi_int(), and write_password_to_file().

889 {
890  struct ast_config *config;
891 
892  if ((config = ast_calloc(1, sizeof(*config))))
894  return config;
895 }
static const char config[]
Definition: cdr_csv.c:57
#define MAX_INCLUDE_LEVEL
Definition: config.c:206
#define ast_calloc(a, b)
Definition: astmm.h:82
int max_include_level
Definition: config.c:244
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 614 of file config.c.

References ast_variable_retrieve().

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

615 {
616  const char *tmp;
617  tmp = ast_variable_retrieve(cfg, cat, var);
618  if (!tmp) {
619  tmp = ast_variable_retrieve(cfg, "general", var);
620  }
621  return tmp;
622 }
const char * ast_variable_retrieve(const struct ast_config *config, const char *category, const char *variable)
Gets a variable.
Definition: config.c:625
#define var
Definition: ast_expr2f.c:606
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 1060 of file config.c.

References ast_config::current.

1061 {
1062  /* cast below is just to silence compiler warning about dropping "const" */
1063  cfg->current = (struct ast_category *) cat;
1064 }
struct ast_category * current
Definition: config.c:241
int ast_config_text_file_save ( const char *  configfile,
const struct ast_config cfg,
const char *  generator 
)

Definition at line 1977 of file config.c.

References ao2_container_alloc, ao2_ref, ast_debug, AST_LIST_EMPTY, AST_LIST_LAST, AST_LIST_TRAVERSE, ast_log(), ast_verb, ast_variable::blanklines, ast_comment::cmt, errno, ast_config_include::exec, ast_config_include::exec_file, f, ast_variable::file, ast_category::file, gen_header(), hash_string(), hashtab_compare_strings(), ast_category::ignored, ast_config_include::include_location_file, ast_config_include::include_location_lineno, ast_config_include::included_file, ast_config::includes, insert_leading_blank_lines(), ast_category_template_instance::inst, ast_variable::lineno, ast_category::lineno, LOG_ERROR, make_fn(), ast_variable::name, ast_category_template_instance::name, ast_category::name, ast_comment::next, ast_variable::next, ast_category::next, ast_config_include::next, ast_variable::object, option_debug, ast_config_include::output, ast_variable::precomments, ast_category::precomments, ast_category::root, ast_config::root, ast_variable::sameline, ast_category::sameline, set_fn(), ast_category::template_instances, ast_variable::trailing, ast_category::trailing, ast_variable::value, and var.

Referenced by action_updateconfig(), config_text_file_save(), vm_change_password(), vm_forwardoptions(), and write_password_to_file().

1978 {
1979  FILE *f;
1980  char fn[PATH_MAX];
1981  struct ast_variable *var;
1982  struct ast_category *cat;
1983  struct ast_comment *cmt;
1984  struct ast_config_include *incl;
1985  int blanklines = 0;
1986  struct ao2_container *fileset;
1987  struct inclfile *fi;
1988 
1990  if (!fileset) {
1991  /* Container creation failed. */
1992  return -1;
1993  }
1994 
1995  /* Check all the files for write access before attempting to modify any of them */
1996  for (incl = cfg->includes; incl; incl = incl->next) {
1997  /* reset all the output flags in case this isn't our first time saving this data */
1998  incl->output = 0;
1999  /* now make sure we have write access */
2000  if (!incl->exec) {
2001  make_fn(fn, sizeof(fn), incl->included_file, configfile);
2002  if (access(fn, R_OK | W_OK)) {
2003  ast_log(LOG_ERROR, "Unable to write %s (%s)\n", fn, strerror(errno));
2004  return -1;
2005  }
2006  }
2007  }
2008 
2009  /* now make sure we have write access to the main config file */
2010  make_fn(fn, sizeof(fn), 0, configfile);
2011  if (access(fn, R_OK | W_OK)) {
2012  ast_log(LOG_ERROR, "Unable to write %s (%s)\n", fn, strerror(errno));
2013  return -1;
2014  }
2015 
2016  /* Now that we know we have write access to all files, it's safe to start truncating them */
2017 
2018  /* go thru all the inclusions and make sure all the files involved (configfile plus all its inclusions)
2019  are all truncated to zero bytes and have that nice header*/
2020  for (incl = cfg->includes; incl; incl = incl->next) {
2021  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*/
2022  /* normally, fn is just set to incl->included_file, prepended with config dir if relative */
2023  fi = set_fn(fn, sizeof(fn), incl->included_file, configfile, fileset);
2024  f = fopen(fn, "w");
2025  if (f) {
2026  gen_header(f, configfile, fn, generator);
2027  fclose(f); /* this should zero out the file */
2028  } else {
2029  ast_log(LOG_ERROR, "Unable to write %s (%s)\n", fn, strerror(errno));
2030  }
2031  if (fi) {
2032  ao2_ref(fi, -1);
2033  }
2034  }
2035  }
2036 
2037  /* just set fn to absolute ver of configfile */
2038  fi = set_fn(fn, sizeof(fn), 0, configfile, fileset);
2039  if (
2040 #ifdef __CYGWIN__
2041  (f = fopen(fn, "w+"))
2042 #else
2043  (f = fopen(fn, "w"))
2044 #endif
2045  ) {
2046  ast_verb(2, "Saving '%s': ", fn);
2047  gen_header(f, configfile, fn, generator);
2048  cat = cfg->root;
2049  fclose(f);
2050  if (fi) {
2051  ao2_ref(fi, -1);
2052  }
2053 
2054  /* from here out, we open each involved file and concat the stuff we need to add to the end and immediately close... */
2055  /* since each var, cat, and associated comments can come from any file, we have to be
2056  mobile, and open each file, print, and close it on an entry-by-entry basis */
2057 
2058  while (cat) {
2059  fi = set_fn(fn, sizeof(fn), cat->file, configfile, fileset);
2060  f = fopen(fn, "a");
2061  if (!f) {
2062  ast_log(LOG_ERROR, "Unable to write %s (%s)\n", fn, strerror(errno));
2063  if (fi) {
2064  ao2_ref(fi, -1);
2065  }
2066  ao2_ref(fileset, -1);
2067  return -1;
2068  }
2069 
2070  /* dump any includes that happen before this category header */
2071  for (incl=cfg->includes; incl; incl = incl->next) {
2072  if (strcmp(incl->include_location_file, cat->file) == 0){
2073  if (cat->lineno > incl->include_location_lineno && !incl->output) {
2074  if (incl->exec)
2075  fprintf(f,"#exec \"%s\"\n", incl->exec_file);
2076  else
2077  fprintf(f,"#include \"%s\"\n", incl->included_file);
2078  incl->output = 1;
2079  }
2080  }
2081  }
2082 
2083  insert_leading_blank_lines(f, fi, cat->precomments, cat->lineno);
2084  /* Dump section with any appropriate comment */
2085  for (cmt = cat->precomments; cmt; cmt=cmt->next) {
2086  char *cmtp = cmt->cmt;
2087  while (cmtp && *cmtp == ';' && *(cmtp+1) == '!') {
2088  char *cmtp2 = strchr(cmtp+1, '\n');
2089  if (cmtp2)
2090  cmtp = cmtp2+1;
2091  else cmtp = 0;
2092  }
2093  if (cmtp)
2094  fprintf(f,"%s", cmtp);
2095  }
2096  fprintf(f, "[%s]", cat->name);
2097  if (cat->ignored || !AST_LIST_EMPTY(&cat->template_instances)) {
2098  fprintf(f, "(");
2099  if (cat->ignored) {
2100  fprintf(f, "!");
2101  }
2102  if (cat->ignored && !AST_LIST_EMPTY(&cat->template_instances)) {
2103  fprintf(f, ",");
2104  }
2105  if (!AST_LIST_EMPTY(&cat->template_instances)) {
2108  fprintf(f,"%s",x->name);
2109  if (x != AST_LIST_LAST(&cat->template_instances))
2110  fprintf(f,",");
2111  }
2112  }
2113  fprintf(f, ")");
2114  }
2115  for(cmt = cat->sameline; cmt; cmt=cmt->next)
2116  {
2117  fprintf(f,"%s", cmt->cmt);
2118  }
2119  if (!cat->sameline)
2120  fprintf(f,"\n");
2121  for (cmt = cat->trailing; cmt; cmt=cmt->next) {
2122  if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
2123  fprintf(f,"%s", cmt->cmt);
2124  }
2125  fclose(f);
2126  if (fi) {
2127  ao2_ref(fi, -1);
2128  }
2129 
2130  var = cat->root;
2131  while (var) {
2133  int found = 0;
2135  struct ast_variable *v;
2136  for (v = x->inst->root; v; v = v->next) {
2137  if (!strcasecmp(var->name, v->name) && !strcmp(var->value, v->value)) {
2138  found = 1;
2139  break;
2140  }
2141  }
2142  if (found)
2143  break;
2144  }
2145  if (found) {
2146  var = var->next;
2147  continue;
2148  }
2149  fi = set_fn(fn, sizeof(fn), var->file, configfile, fileset);
2150  f = fopen(fn, "a");
2151  if (!f) {
2152  ast_debug(1, "Unable to open for writing: %s\n", fn);
2153  ast_verb(2, "Unable to write %s (%s)", fn, strerror(errno));
2154  if (fi) {
2155  ao2_ref(fi, -1);
2156  }
2157  ao2_ref(fileset, -1);
2158  return -1;
2159  }
2160 
2161  /* dump any includes that happen before this category header */
2162  for (incl=cfg->includes; incl; incl = incl->next) {
2163  if (strcmp(incl->include_location_file, var->file) == 0){
2164  if (var->lineno > incl->include_location_lineno && !incl->output) {
2165  if (incl->exec)
2166  fprintf(f,"#exec \"%s\"\n", incl->exec_file);
2167  else
2168  fprintf(f,"#include \"%s\"\n", incl->included_file);
2169  incl->output = 1;
2170  }
2171  }
2172  }
2173 
2174  insert_leading_blank_lines(f, fi, var->precomments, var->lineno);
2175  for (cmt = var->precomments; cmt; cmt=cmt->next) {
2176  if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
2177  fprintf(f,"%s", cmt->cmt);
2178  }
2179  if (var->sameline)
2180  fprintf(f, "%s %s %s %s", var->name, (var->object ? "=>" : "="), var->value, var->sameline->cmt);
2181  else
2182  fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="), var->value);
2183  for (cmt = var->trailing; cmt; cmt=cmt->next) {
2184  if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
2185  fprintf(f,"%s", cmt->cmt);
2186  }
2187  if (var->blanklines) {
2188  blanklines = var->blanklines;
2189  while (blanklines--)
2190  fprintf(f, "\n");
2191  }
2192 
2193  fclose(f);
2194  if (fi) {
2195  ao2_ref(fi, -1);
2196  }
2197 
2198  var = var->next;
2199  }
2200  cat = cat->next;
2201  }
2202  if (!option_debug)
2203  ast_verb(2, "Saved\n");
2204  } else {
2205  ast_debug(1, "Unable to open for writing: %s\n", fn);
2206  ast_verb(2, "Unable to write (%s)", strerror(errno));
2207  if (fi) {
2208  ao2_ref(fi, -1);
2209  }
2210  ao2_ref(fileset, -1);
2211  return -1;
2212  }
2213 
2214  /* Now, for files with trailing #include/#exec statements,
2215  we have to make sure every entry is output */
2216  for (incl=cfg->includes; incl; incl = incl->next) {
2217  if (!incl->output) {
2218  /* open the respective file */
2219  fi = set_fn(fn, sizeof(fn), incl->include_location_file, configfile, fileset);
2220  f = fopen(fn, "a");
2221  if (!f) {
2222  ast_debug(1, "Unable to open for writing: %s\n", fn);
2223  ast_verb(2, "Unable to write %s (%s)", fn, strerror(errno));
2224  if (fi) {
2225  ao2_ref(fi, -1);
2226  }
2227  ao2_ref(fileset, -1);
2228  return -1;
2229  }
2230 
2231  /* output the respective include */
2232  if (incl->exec)
2233  fprintf(f,"#exec \"%s\"\n", incl->exec_file);
2234  else
2235  fprintf(f,"#include \"%s\"\n", incl->included_file);
2236  fclose(f);
2237  incl->output = 1;
2238  if (fi) {
2239  ao2_ref(fi, -1);
2240  }
2241  }
2242  }
2243  ao2_ref(fileset, -1); /* this should destroy the hash container */
2244 
2245  return 0;
2246 }
struct ast_comment * precomments
Definition: config.h:90
int ignored
Definition: config.c:216
char * exec_file
if it&#39;s an exec, you&#39;ll have both the /var/tmp to read, and the original script
Definition: config.c:260
Structure to keep comments for rewriting configuration files.
Definition: config.c:73
int option_debug
Definition: asterisk.c:182
int lineno
Definition: config.h:87
static int hash_string(const void *obj, const int flags)
Definition: config.c:162
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
int object
Definition: config.h:88
#define var
Definition: ast_expr2f.c:606
static void gen_header(FILE *f1, const char *configfile, const char *fn, const char *generator)
Definition: config.c:1840
static int hashtab_compare_strings(void *a, void *b, int flags)
Definition: config.c:182
struct ast_category * next
Definition: config.c:233
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:449
char name[80]
Definition: config.c:215
int lineno
Definition: config.c:223
char * included_file
file name included
Definition: config.c:265
#define ast_verb(level,...)
Definition: logger.h:243
char cmt[0]
Definition: config.c:76
struct ast_comment * trailing
Definition: config.h:92
static void make_fn(char *fn, size_t fn_size, const char *file, const char *configfile)
Definition: config.c:1866
static struct inclfile * set_fn(char *fn, size_t fn_size, const char *file, const char *configfile, struct ao2_container *fileset)
Definition: config.c:1881
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
const char * value
Definition: config.h:79
struct ast_category::template_instance_list template_instances
struct ast_comment * trailing
Definition: config.c:227
struct ast_variable * root
Definition: config.c:229
static void insert_leading_blank_lines(FILE *fp, struct inclfile *fi, struct ast_comment *precomments, int lineno)
Definition: config.c:1936
struct ast_comment * next
Definition: config.c:74
#define ao2_ref(o, delta)
Definition: astobj2.h:472
const char * name
Definition: config.h:77
struct ast_category_template_instance * next
Definition: config.c:211
#define LOG_ERROR
Definition: logger.h:155
static struct ast_generator generator
Definition: app_fax.c:361
const char * file
Definition: config.h:85
struct ast_comment * sameline
Definition: config.c:226
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define AST_LIST_LAST(head)
Returns the last entry contained in a list.
Definition: linkedlists.h:428
int include_location_lineno
Definition: config.c:254
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
int errno
static struct ast_format f[]
Definition: format_g726.c:181
struct ast_comment * precomments
Definition: config.c:225
char * include_location_file
file name in which the include occurs
Definition: config.c:253
#define ao2_container_alloc(arg1, arg2, arg3)
Definition: astobj2.h:734
int blanklines
Definition: config.h:89
struct ast_category * root
Definition: config.c:238
struct ast_comment * sameline
Definition: config.h:91
struct ast_config_include * next
Definition: config.c:269
struct ast_variable * next
Definition: config.h:82
struct ast_config_include * includes
Definition: config.c:245
struct ast_category * inst
Definition: config.c:210
char * file
The file name from whence this declaration was read.
Definition: config.c:222
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 2750 of file config.c.

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

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

2751 {
2752  struct ast_config_engine *eng;
2753  int res = -1, i;
2754  char db[256];
2755  char table[256];
2756  va_list ap;
2757 
2758  va_start(ap, lookup);
2759  for (i = 1; ; i++) {
2760  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
2761  if (eng->destroy_func && !(res = eng->destroy_func(db, table, keyfield, lookup, ap))) {
2762  break;
2763  }
2764  } else {
2765  break;
2766  }
2767  }
2768  va_end(ap);
2769 
2770  return res;
2771 }
realtime_destroy * destroy_func
Definition: config.h:129
Configuration engine structure, used to define realtime drivers.
Definition: config.h:121
static char * table
Definition: cdr_odbc.c:50
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: config.c:2420
static sqlite * db
Definition: cdr_sqlite.c:62
static void ast_destroy_template_list ( struct ast_category cat)
static

Definition at line 754 of file config.c.

References ast_free, AST_LIST_REMOVE_HEAD, and ast_category::template_instances.

Referenced by ast_category_destroy().

755 {
757 
758  while ((x = AST_LIST_REMOVE_HEAD(&cat->template_instances, next)))
759  ast_free(x);
760 }
struct ast_category::template_instance_list template_instances
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:818
struct ast_category_template_instance * next
Definition: config.c:211
#define ast_free(a)
Definition: astmm.h:97
struct ast_config_include* ast_include_find ( struct ast_config conf,
const char *  included_file 
)

Definition at line 472 of file config.c.

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

Referenced by ast_include_new().

473 {
474  struct ast_config_include *x;
475  for (x=conf->includes;x;x=x->next) {
476  if (strcmp(x->included_file,included_file) == 0)
477  return x;
478  }
479  return 0;
480 }
char * included_file
file name included
Definition: config.c:265
struct ast_config_include * next
Definition: config.c:269
struct ast_config_include * includes
Definition: config.c:245
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 332 of file config.c.

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

Referenced by process_text_line().

333 {
334  /* a file should be included ONCE. Otherwise, if one of the instances is changed,
335  * then all be changed. -- how do we know to include it? -- Handling modified
336  * instances is possible, I'd have
337  * to create a new master for each instance. */
338  struct ast_config_include *inc;
339  struct stat statbuf;
340 
341  inc = ast_include_find(conf, included_file);
342  if (inc) {
343  do {
344  inc->inclusion_count++;
345  snprintf(real_included_file_name, real_included_file_name_size, "%s~~%d", included_file, inc->inclusion_count);
346  } while (stat(real_included_file_name, &statbuf) == 0);
347  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);
348  } else
349  *real_included_file_name = 0;
350 
351  inc = ast_calloc(1,sizeof(struct ast_config_include));
352  if (!inc) {
353  return NULL;
354  }
355  inc->include_location_file = ast_strdup(from_file);
356  inc->include_location_lineno = from_lineno;
357  if (!ast_strlen_zero(real_included_file_name))
358  inc->included_file = ast_strdup(real_included_file_name);
359  else
360  inc->included_file = ast_strdup(included_file);
361 
362  inc->exec = is_exec;
363  if (is_exec)
364  inc->exec_file = ast_strdup(exec_file);
365 
366  if (!inc->include_location_file
367  || !inc->included_file
368  || (is_exec && !inc->exec_file)) {
370  return NULL;
371  }
372 
373  /* attach this new struct to the conf struct */
374  inc->next = conf->includes;
375  conf->includes = inc;
376 
377  return inc;
378 }
struct ast_config_include * ast_include_find(struct ast_config *conf, const char *included_file)
Definition: config.c:472
#define ast_strdup(a)
Definition: astmm.h:109
#define LOG_WARNING
Definition: logger.h:144
static void ast_includes_destroy(struct ast_config_include *incls)
Definition: config.c:775
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ast_calloc(a, b)
Definition: astmm.h:82
struct ast_config_include * includes
Definition: config.c:245
void ast_include_rename ( struct ast_config conf,
const char *  from_file,
const char *  to_file 
)

Definition at line 380 of file config.c.

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

Referenced by action_updateconfig().

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

Definition at line 775 of file config.c.

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

776 {
777  struct ast_config_include *incl,*inclnext;
778 
779  for (incl=incls; incl; incl = inclnext) {
780  inclnext = incl->next;
782  ast_free(incl->exec_file);
783  ast_free(incl->included_file);
784  ast_free(incl);
785  }
786 }
char * exec_file
if it&#39;s an exec, you&#39;ll have both the /var/tmp to read, and the original script
Definition: config.c:260
char * included_file
file name included
Definition: config.c:265
#define ast_free(a)
Definition: astmm.h:97
char * include_location_file
file name in which the include occurs
Definition: config.c:253
struct ast_config_include * next
Definition: config.c:269
struct ast_variable* ast_load_realtime ( 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.

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 2548 of file config.c.

References ast_load_realtime_helper(), ast_strlen_zero(), ast_variable_destroy(), cache_file_include::next, ast_variable::next, and ast_variable::value.

Referenced by conf_run(), copy_plain_file(), find_conf_realtime(), find_realtime(), find_realtime_gw(), find_user_realtime(), leave_queue(), load_realtime_queue(), local_ast_moh_start(), queue_function_queuewaitingcount(), realtime_alias(), realtime_peer(), realtime_peer_by_addr(), realtime_peer_by_name(), realtime_peer_get_sippeer_helper(), realtime_switch_common(), realtime_user(), and rt_extend_conf().

2549 {
2550  struct ast_variable *res;
2551  struct ast_variable *cur;
2552  struct ast_variable **prev;
2553  va_list ap;
2554 
2555  va_start(ap, family);
2556  res = ast_load_realtime_helper(family, ap);
2557  va_end(ap);
2558 
2559  /* Filter the list. */
2560  prev = &res;
2561  cur = res;
2562  while (cur) {
2563  if (ast_strlen_zero(cur->value)) {
2564  /* Eliminate empty entries */
2565  struct ast_variable *next;
2566 
2567  next = cur->next;
2568  *prev = next;
2569  ast_variable_destroy(cur);
2570  cur = next;
2571  } else {
2572  /* Make blank entries empty and keep them. */
2573  if (cur->value[0] == ' ' && cur->value[1] == '\0') {
2574  char *vptr = (char *) cur->value;
2575 
2576  vptr[0] = '\0';
2577  }
2578 
2579  prev = &cur->next;
2580  cur = cur->next;
2581  }
2582  }
2583  return res;
2584 }
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
static struct ast_variable * ast_load_realtime_helper(const char *family, va_list ap)
Definition: config.c:2515
const char * value
Definition: config.h:79
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
static void ast_variable_destroy(struct ast_variable *doomed)
Definition: config.c:532
struct ast_variable * next
Definition: config.h:82
struct ast_variable* ast_load_realtime_all ( const char *  family,
  ... 
)

Definition at line 2536 of file config.c.

References ast_load_realtime_helper().

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

2537 {
2538  struct ast_variable *res;
2539  va_list ap;
2540 
2541  va_start(ap, family);
2542  res = ast_load_realtime_helper(family, ap);
2543  va_end(ap);
2544 
2545  return res;
2546 }
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
static struct ast_variable * ast_load_realtime_helper(const char *family, va_list ap)
Definition: config.c:2515
static struct ast_variable* ast_load_realtime_helper ( const char *  family,
va_list  ap 
)
static

Definition at line 2515 of file config.c.

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

Referenced by ast_load_realtime(), and ast_load_realtime_all().

2516 {
2517  struct ast_config_engine *eng;
2518  char db[256];
2519  char table[256];
2520  struct ast_variable *res=NULL;
2521  int i;
2522 
2523  for (i = 1; ; i++) {
2524  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
2525  if (eng->realtime_func && (res = eng->realtime_func(db, table, ap))) {
2526  return res;
2527  }
2528  } else {
2529  return NULL;
2530  }
2531  }
2532 
2533  return res;
2534 }
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
Configuration engine structure, used to define realtime drivers.
Definition: config.h:121
static char * table
Definition: cdr_odbc.c:50
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: config.c:2420
static sqlite * db
Definition: cdr_sqlite.c:62
realtime_var_get * realtime_func
Definition: config.h:124
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 2650 of file config.c.

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

Referenced by __queues_show(), conf_exec(), find_realtime(), get_insecure_variable_from_sippeers(), get_insecure_variable_from_sipregs(), load_realtime_queue(), queues_data_provider_get(), realtime_directory(), realtime_switch_common(), show_users_realtime(), and update_realtime_members().

2651 {
2652  struct ast_config_engine *eng;
2653  char db[256];
2654  char table[256];
2655  struct ast_config *res = NULL;
2656  va_list ap;
2657  int i;
2658 
2659  va_start(ap, family);
2660  for (i = 1; ; i++) {
2661  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
2662  if (eng->realtime_multi_func && (res = eng->realtime_multi_func(db, table, ap))) {
2663  /* If we were returned an empty cfg, destroy it and return NULL */
2664  if (!res->root) {
2665  ast_config_destroy(res);
2666  res = NULL;
2667  }
2668  break;
2669  }
2670  } else {
2671  break;
2672  }
2673  }
2674  va_end(ap);
2675 
2676  return res;
2677 }
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: config.c:1037
Configuration engine structure, used to define realtime drivers.
Definition: config.h:121
static char * table
Definition: cdr_odbc.c:50
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: config.c:2420
static sqlite * db
Definition: cdr_sqlite.c:62
realtime_multi_get * realtime_multi_func
Definition: config.h:125
struct ast_category * root
Definition: config.c:238
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 2805 of file config.c.

References ast_debug, ast_gethostbyname(), ast_inet_ntoa(), ast_skip_blanks(), ast_sockaddr_parse(), ast_sockaddr_stringify(), ast_strdupa, ast_strlen_zero(), errno, hp, INT32_MAX, INT32_MIN, 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_TYPE, PARSE_UINT32, strsep(), and UINT32_MAX.

Referenced by __ast_http_load(), ast_tls_read_conf(), check_via_response(), gtalk_load_config(), and reload_config().

2807 {
2808  va_list ap;
2809  int error = 0;
2810 
2811  va_start(ap, p_result);
2812  switch (flags & PARSE_TYPE) {
2813  case PARSE_INT32:
2814  {
2815  long int x = 0;
2816  int32_t *result = p_result;
2817  int32_t def = result ? *result : 0, high = INT32_MAX, low = INT32_MIN;
2818  char *endptr = NULL;
2819 
2820  /* optional arguments: default value and/or (low, high) */
2821  if (flags & PARSE_DEFAULT) {
2822  def = va_arg(ap, int32_t);
2823  }
2824  if (flags & (PARSE_IN_RANGE | PARSE_OUT_RANGE)) {
2825  low = va_arg(ap, int32_t);
2826  high = va_arg(ap, int32_t);
2827  }
2828  if (ast_strlen_zero(arg)) {
2829  error = 1;
2830  goto int32_done;
2831  }
2832  errno = 0;
2833  x = strtol(arg, &endptr, 0);
2834  if (*endptr || errno || x < INT32_MIN || x > INT32_MAX) {
2835  /* Parse error, or type out of int32_t bounds */
2836  error = 1;
2837  goto int32_done;
2838  }
2839  error = (x < low) || (x > high);
2840  if (flags & PARSE_OUT_RANGE) {
2841  error = !error;
2842  }
2843 int32_done:
2844  if (result) {
2845  *result = error ? def : x;
2846  }
2847 
2848  ast_debug(3, "extract int from [%s] in [%d, %d] gives [%ld](%d)\n",
2849  arg, low, high, result ? *result : x, error);
2850  break;
2851  }
2852 
2853  case PARSE_UINT32:
2854  {
2855  unsigned long int x = 0;
2856  uint32_t *result = p_result;
2857  uint32_t def = result ? *result : 0, low = 0, high = UINT32_MAX;
2858  char *endptr = NULL;
2859 
2860  /* optional argument: first default value, then range */
2861  if (flags & PARSE_DEFAULT) {
2862  def = va_arg(ap, uint32_t);
2863  }
2864  if (flags & (PARSE_IN_RANGE|PARSE_OUT_RANGE)) {
2865  /* range requested, update bounds */
2866  low = va_arg(ap, uint32_t);
2867  high = va_arg(ap, uint32_t);
2868  }
2869 
2870  if (ast_strlen_zero(arg)) {
2871  error = 1;
2872  goto uint32_done;
2873  }
2874  /* strtoul will happilly and silently negate negative numbers */
2875  arg = ast_skip_blanks(arg);
2876  if (*arg == '-') {
2877  error = 1;
2878  goto uint32_done;
2879  }
2880  errno = 0;
2881  x = strtoul(arg, &endptr, 0);
2882  if (*endptr || errno || x > UINT32_MAX) {
2883  error = 1;
2884  goto uint32_done;
2885  }
2886  error = (x < low) || (x > high);
2887  if (flags & PARSE_OUT_RANGE) {
2888  error = !error;
2889  }
2890 uint32_done:
2891  if (result) {
2892  *result = error ? def : x;
2893  }
2894  ast_debug(3, "extract uint from [%s] in [%u, %u] gives [%lu](%d)\n",
2895  arg, low, high, result ? *result : x, error);
2896  break;
2897  }
2898 
2899  case PARSE_DOUBLE:
2900  {
2901  double *result = p_result;
2902  double x = 0, def = result ? *result : 0, low = -HUGE_VAL, high = HUGE_VAL;
2903  char *endptr = NULL;
2904 
2905  /* optional argument: first default value, then range */
2906  if (flags & PARSE_DEFAULT) {
2907  def = va_arg(ap, double);
2908  }
2909  if (flags & (PARSE_IN_RANGE | PARSE_OUT_RANGE)) {
2910  /* range requested, update bounds */
2911  low = va_arg(ap, double);
2912  high = va_arg(ap, double);
2913  }
2914  if (ast_strlen_zero(arg)) {
2915  error = 1;
2916  goto double_done;
2917  }
2918  errno = 0;
2919  x = strtod(arg, &endptr);
2920  if (*endptr || errno == ERANGE) {
2921  error = 1;
2922  goto double_done;
2923  }
2924  error = (x < low) || (x > high);
2925  if (flags & PARSE_OUT_RANGE) {
2926  error = !error;
2927  }
2928 double_done:
2929  if (result) {
2930  *result = error ? def : x;
2931  }
2932  ast_debug(3, "extract double from [%s] in [%f, %f] gives [%f](%d)\n",
2933  arg, low, high, result ? *result : x, error);
2934  break;
2935  }
2936  case PARSE_ADDR:
2937  {
2938  struct ast_sockaddr *addr = (struct ast_sockaddr *)p_result;
2939 
2940  if (!ast_sockaddr_parse(addr, arg, flags & PARSE_PORT_MASK)) {
2941  error = 1;
2942  }
2943 
2944  ast_debug(3, "extract addr from %s gives %s(%d)\n",
2945  arg, ast_sockaddr_stringify(addr), error);
2946 
2947  break;
2948  }
2949  case PARSE_INADDR: /* TODO Remove this (use PARSE_ADDR instead). */
2950  {
2951  char *port, *buf;
2952  struct sockaddr_in _sa_buf; /* buffer for the result */
2953  struct sockaddr_in *sa = p_result ?
2954  (struct sockaddr_in *)p_result : &_sa_buf;
2955  /* default is either the supplied value or the result itself */
2956  struct sockaddr_in *def = (flags & PARSE_DEFAULT) ?
2957  va_arg(ap, struct sockaddr_in *) : sa;
2958  struct hostent *hp;
2959  struct ast_hostent ahp;
2960 
2961  memset(&_sa_buf, '\0', sizeof(_sa_buf)); /* clear buffer */
2962  /* duplicate the string to strip away the :port */
2963  port = ast_strdupa(arg);
2964  buf = strsep(&port, ":");
2965  sa->sin_family = AF_INET; /* assign family */
2966  /*
2967  * honor the ports flag setting, assign default value
2968  * in case of errors or field unset.
2969  */
2970  flags &= PARSE_PORT_MASK; /* the only flags left to process */
2971  if (port) {
2972  if (flags == PARSE_PORT_FORBID) {
2973  error = 1; /* port was forbidden */
2974  sa->sin_port = def->sin_port;
2975  } else if (flags == PARSE_PORT_IGNORE)
2976  sa->sin_port = def->sin_port;
2977  else /* accept or require */
2978  sa->sin_port = htons(strtol(port, NULL, 0));
2979  } else {
2980  sa->sin_port = def->sin_port;
2981  if (flags == PARSE_PORT_REQUIRE)
2982  error = 1;
2983  }
2984  /* Now deal with host part, even if we have errors before. */
2985  hp = ast_gethostbyname(buf, &ahp);
2986  if (hp) /* resolved successfully */
2987  memcpy(&sa->sin_addr, hp->h_addr, sizeof(sa->sin_addr));
2988  else {
2989  error = 1;
2990  sa->sin_addr = def->sin_addr;
2991  }
2992  ast_debug(3,
2993  "extract inaddr from [%s] gives [%s:%d](%d)\n",
2994  arg, ast_inet_ntoa(sa->sin_addr),
2995  ntohs(sa->sin_port), error);
2996  break;
2997  }
2998  }
2999  va_end(ap);
3000  return error;
3001 }
char * strsep(char **str, const char *delims)
int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
Parse an IPv4 or IPv6 address string.
Definition: netsock2.c:198
#define UINT32_MAX
Definition: ast_expr2f.c:87
#define INT32_MAX
Definition: ast_expr2f.c:78
Socket address structure.
Definition: netsock2.h:63
#define INT32_MIN
Definition: ast_expr2f.c:69
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
static struct ast_hostent ahp
Definition: chan_skinny.c:1047
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition: netsock2.h:210
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
Definition: strings.h:97
int errno
const char * ast_inet_ntoa(struct in_addr ia)
thread-safe replacement for inet_ntoa().
Definition: utils.c:564
struct hostent * ast_gethostbyname(const char *host, struct ast_hostent *hp)
Thread-safe gethostbyname function to use in Asterisk.
Definition: utils.c:195
static struct hostent * hp
Definition: chan_skinny.c:1048
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 This function modifies the original buffer

Definition at line 2773 of file config.c.

Referenced by realtime_multi_pgsql(), and realtime_pgsql().

2774 {
2775  char *orig = chunk;
2776  for (; *chunk; chunk++) {
2777  if (*chunk == '^' && strchr("0123456789ABCDEFabcdef", chunk[1]) && strchr("0123456789ABCDEFabcdef", chunk[2])) {
2778  sscanf(chunk + 1, "%02hhX", (unsigned char *)chunk);
2779  memmove(chunk + 1, chunk + 3, strlen(chunk + 3) + 1);
2780  }
2781  }
2782  return orig;
2783 }
int ast_realtime_enabled ( void  )

Check if there's any realtime engines loaded.

Definition at line 2601 of file config.c.

References config_maps.

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

2602 {
2603  return config_maps ? 1 : 0;
2604 }
static struct ast_config_map * config_maps
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 2785 of file config.c.

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

2786 {
2787  if (!strchr(chunk, ';') && !strchr(chunk, '^')) {
2788  ast_str_set(dest, maxlen, "%s", chunk);
2789  } else {
2790  ast_str_reset(*dest);
2791  for (; *chunk; chunk++) {
2792  if (strchr(";^", *chunk)) {
2793  ast_str_append(dest, maxlen, "^%02hhX", *chunk);
2794  } else {
2795  ast_str_append(dest, maxlen, "%c", *chunk);
2796  }
2797  }
2798  }
2799  return ast_str_buffer(*dest);
2800 }
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:497
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:900
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:874
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:436
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.

Definition at line 2606 of file config.c.

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

2607 {
2608  struct ast_config_engine *eng;
2609  char db[256];
2610  char table[256];
2611  va_list ap;
2612  int res = -1, i;
2613 
2614  va_start(ap, family);
2615  for (i = 1; ; i++) {
2616  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
2617  /* If the require succeeds, it returns 0. */
2618  if (eng->require_func && !(res = eng->require_func(db, table, ap))) {
2619  break;
2620  }
2621  } else {
2622  break;
2623  }
2624  }
2625  va_end(ap);
2626 
2627  return res;
2628 }
Configuration engine structure, used to define realtime drivers.
Definition: config.h:121
static char * table
Definition: cdr_odbc.c:50
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: config.c:2420
realtime_require * require_func
Definition: config.h:130
static sqlite * db
Definition: cdr_sqlite.c:62
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 2726 of file config.c.

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

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

2727 {
2728  struct ast_config_engine *eng;
2729  int res = -1, i;
2730  char db[256];
2731  char table[256];
2732  va_list ap;
2733 
2734  va_start(ap, family);
2735  for (i = 1; ; i++) {
2736  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
2737  /* If the store succeeds, it returns 0. */
2738  if (eng->store_func && !(res = eng->store_func(db, table, ap))) {
2739  break;
2740  }
2741  } else {
2742  break;
2743  }
2744  }
2745  va_end(ap);
2746 
2747  return res;
2748 }
realtime_store * store_func
Definition: config.h:128
Configuration engine structure, used to define realtime drivers.
Definition: config.h:121
static char * table
Definition: cdr_odbc.c:50
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: config.c:2420
static sqlite * db
Definition: cdr_sqlite.c:62
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 2630 of file config.c.

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

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

2631 {
2632  struct ast_config_engine *eng;
2633  char db[256];
2634  char table[256];
2635  int res = -1, i;
2636 
2637  for (i = 1; ; i++) {
2638  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
2639  if (eng->unload_func) {
2640  /* Do this for ALL engines */
2641  res = eng->unload_func(db, table);
2642  }
2643  } else {
2644  break;
2645  }
2646  }
2647  return res;
2648 }
realtime_unload * unload_func
Definition: config.h:131
Configuration engine structure, used to define realtime drivers.
Definition: config.h:121
static char * table
Definition: cdr_odbc.c:50
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: config.c:2420
static sqlite * db
Definition: cdr_sqlite.c:62
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 2703 of file config.c.

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

Referenced by change_password_realtime(), and cli_realtime_update2().

2704 {
2705  struct ast_config_engine *eng;
2706  int res = -1, i;
2707  char db[256];
2708  char table[256];
2709  va_list ap;
2710 
2711  va_start(ap, family);
2712  for (i = 1; ; i++) {
2713  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
2714  if (eng->update2_func && !(res = eng->update2_func(db, table, ap))) {
2715  break;
2716  }
2717  } else {
2718  break;
2719  }
2720  }
2721  va_end(ap);
2722 
2723  return res;
2724 }
Configuration engine structure, used to define realtime drivers.
Definition: config.h:121
static char * table
Definition: cdr_odbc.c:50
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: config.c:2420
static sqlite * db
Definition: cdr_sqlite.c:62
realtime_update2 * update2_func
Definition: config.h:127
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 2679 of file config.c.

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

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

2680 {
2681  struct ast_config_engine *eng;
2682  int res = -1, i;
2683  char db[256];
2684  char table[256];
2685  va_list ap;
2686 
2687  va_start(ap, lookup);
2688  for (i = 1; ; i++) {
2689  if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) {
2690  /* If the update succeeds, it returns 0. */
2691  if (eng->update_func && !(res = eng->update_func(db, table, keyfield, lookup, ap))) {
2692  break;
2693  }
2694  } else {
2695  break;
2696  }
2697  }
2698  va_end(ap);
2699 
2700  return res;
2701 }
realtime_update * update_func
Definition: config.h:126
Configuration engine structure, used to define realtime drivers.
Definition: config.h:121
static char * table
Definition: cdr_odbc.c:50
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: config.c:2420
static sqlite * db
Definition: cdr_sqlite.c:62
void ast_variable_append ( struct ast_category category,
struct ast_variable variable 
)

Definition at line 483 of file config.c.

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

Referenced by add_cfg_entry(), add_rt_multi_cfg_entry(), config_curl(), config_ldap(), config_odbc(), config_pgsql(), handle_updates(), inherit_category(), move_variables(), process_text_line(), realtime_directory(), realtime_multi_curl(), realtime_multi_ldap(), realtime_multi_odbc(), realtime_multi_pgsql(), vm_change_password(), and write_password_to_file().

484 {
485  if (!variable)
486  return;
487  if (category->last)
488  category->last->next = variable;
489  else
490  category->root = variable;
491  category->last = variable;
492  while (category->last->next)
493  category->last = category->last->next;
494 }
struct ast_variable * last
Definition: config.c:231
struct ast_variable * root
Definition: config.c:229
struct ast_variable * next
Definition: config.h:82
struct ast_variable* ast_variable_browse ( const struct ast_config config,
const char *  category 
)

Goes through variables.

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

Return values
ast_variablelist on success
NULLon failure

Definition at line 597 of file config.c.

References ast_category_get(), ast_config::last_browse, ast_category::name, and ast_category::root.

Referenced by __ast_http_load(), __ast_http_post_load(), __init_manager(), _dsp_init(), action_getconfig(), action_getconfigjson(), actual_load_config(), adsi_load(), aji_load_config(), ast_cli_perms_init(), ast_plc_reload(), ast_readconfig(), ast_variable_retrieve(), ast_xmldoc_load_documentation(), build_calendar(), build_device(), build_event_channel(), caldav_load_calendar(), conf_exec(), config_load(), config_module(), do_say(), ewscal_load_calendar(), exchangecal_load_calendar(), find_conf(), gtalk_load_config(), handle_cli_dialplan_save(), iax_template_parse(), ical_load_calendar(), init_logger_chain(), jingle_load_config(), load_config(), load_module(), load_modules(), load_moh_classes(), load_odbc_config(), load_pktccops_config(), misdn_cfg_init(), odbc_load_module(), osp_create_provider(), parse_config(), parse_tone_zone(), pbx_load_config(), process_config(), read_agent_config(), read_config_maps(), reload(), reload_config(), reload_followme(), reload_module(), reload_queue_rules(), reload_single_queue(), run_startup_commands(), search_directory_sub(), set_config(), setup_dahdi_int(), show_users_realtime(), sip_cli_notify(), sla_build_station(), sla_build_trunk(), smdi_load(), store_config(), and tds_load_module().

598 {
599  struct ast_category *cat = NULL;
600 
601  if (!category) {
602  return NULL;
603  }
604 
605  if (config->last_browse && (config->last_browse->name == category)) {
606  cat = config->last_browse;
607  } else {
608  cat = ast_category_get(config, category);
609  }
610 
611  return (cat) ? cat->root : NULL;
612 }
char name[80]
Definition: config.c:215
struct ast_category * last_browse
Definition: config.c:242
struct ast_category * ast_category_get(const struct ast_config *config, const char *category_name)
Retrieve a category if it exists.
Definition: config.c:709
struct ast_variable * root
Definition: config.c:229
int ast_variable_delete ( struct ast_category category,
const char *  variable,
const char *  match,
const char *  line 
)

Definition at line 897 of file config.c.

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

Referenced by handle_updates().

898 {
899  struct ast_variable *cur, *prev=NULL, *curn;
900  int res = -1;
901  int num_item = 0;
902  int req_item;
903 
904  req_item = -1;
905  if (!ast_strlen_zero(line)) {
906  /* Requesting to delete by item number. */
907  if (sscanf(line, "%30d", &req_item) != 1
908  || req_item < 0) {
909  /* Invalid item number to delete. */
910  return -1;
911  }
912  }
913 
914  prev = NULL;
915  cur = category->root;
916  while (cur) {
917  curn = cur->next;
918  /* Delete by item number or by variable name with optional value. */
919  if ((0 <= req_item && num_item == req_item)
920  || (req_item < 0 && !strcasecmp(cur->name, variable)
921  && (ast_strlen_zero(match) || !strcasecmp(cur->value, match)))) {
922  if (prev) {
923  prev->next = cur->next;
924  if (cur == category->last)
925  category->last = prev;
926  } else {
927  category->root = cur->next;
928  if (cur == category->last)
929  category->last = NULL;
930  }
932  res = 0;
933  } else
934  prev = cur;
935 
936  cur = curn;
937  ++num_item;
938  }
939  return res;
940 }
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
struct ast_variable * last
Definition: config.c:231
const char * value
Definition: config.h:79
struct ast_variable * root
Definition: config.c:229
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
const char * name
Definition: config.h:77
static void ast_variable_destroy(struct ast_variable *doomed)
Definition: config.c:532
struct ast_variable * next
Definition: config.h:82
static int match(struct sockaddr_in *sin, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Definition: chan_iax2.c:2069
static void ast_variable_destroy ( struct ast_variable doomed)
static

Definition at line 532 of file config.c.

References ast_comment_destroy(), ast_free, ast_variable::precomments, ast_variable::sameline, and ast_variable::trailing.

Referenced by ast_include_rename(), ast_load_realtime(), ast_variable_delete(), ast_variable_update(), and ast_variables_destroy().

533 {
535  ast_comment_destroy(&doomed->sameline);
536  ast_comment_destroy(&doomed->trailing);
537  ast_free(doomed);
538 }
struct ast_comment * precomments
Definition: config.h:90
static void ast_comment_destroy(struct ast_comment **comment)
Definition: config.c:520
struct ast_comment * trailing
Definition: config.h:92
#define ast_free(a)
Definition: astmm.h:97
struct ast_comment * sameline
Definition: config.h:91
void ast_variable_insert ( struct ast_category category,
struct ast_variable variable,
const char *  line 
)

Definition at line 496 of file config.c.

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

Referenced by handle_updates().

497 {
498  struct ast_variable *cur = category->root;
499  int lineno;
500  int insertline;
501 
502  if (!variable || sscanf(line, "%30d", &insertline) != 1) {
503  return;
504  }
505  if (!insertline) {
506  variable->next = category->root;
507  category->root = variable;
508  } else {
509  for (lineno = 1; lineno < insertline; lineno++) {
510  cur = cur->next;
511  if (!cur->next) {
512  break;
513  }
514  }
515  variable->next = cur->next;
516  cur->next = variable;
517  }
518 }
int lineno
Definition: config.h:87
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
struct ast_variable * root
Definition: config.c:229
struct ast_variable * next
Definition: config.h:82
static void ast_variable_move ( struct ast_variable dst_var,
struct ast_variable src_var 
)
static

Definition at line 319 of file config.c.

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

Referenced by ast_include_rename(), and ast_variable_update().

320 {
321  dst_var->lineno = src_var->lineno;
322  dst_var->object = src_var->object;
323  dst_var->blanklines = src_var->blanklines;
324  dst_var->precomments = src_var->precomments;
325  src_var->precomments = NULL;
326  dst_var->sameline = src_var->sameline;
327  src_var->sameline = NULL;
328  dst_var->trailing = src_var->trailing;
329  src_var->trailing = NULL;
330 }
struct ast_comment * precomments
Definition: config.h:90
int lineno
Definition: config.h:87
int object
Definition: config.h:88
struct ast_comment * trailing
Definition: config.h:92
int blanklines
Definition: config.h:89
struct ast_comment * sameline
Definition: config.h:91
struct ast_variable* ast_variable_new ( const char *  name,
const char *  value,
const char *  filename 
)

Definition at line 278 of file config.c.

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

Referenced by add_cfg_entry(), add_rt_cfg_entry(), add_rt_multi_cfg_entry(), add_var(), apply_outgoing(), ast_channeltype_list(), ast_http_get_post_vars(), ast_include_rename(), ast_variable_update(), ast_variables_dup(), build_user(), check_access(), config_curl(), config_ldap(), config_odbc(), config_pgsql(), copy_vars(), create_vmaccount(), dup_vars(), handle_updates(), handle_uri(), httpd_helper_thread(), iax_parse_ies(), ldap_table_config_add_attribute(), man_do_variable_value(), manager_sipnotify(), mkintf(), parkandannounce_exec(), parse_cookies(), process_dahdi(), process_text_line(), realtime_curl(), realtime_directory(), realtime_ldap_entry_to_var(), realtime_ldap_result_to_vars(), realtime_multi_curl(), realtime_multi_odbc(), realtime_multi_pgsql(), realtime_odbc(), realtime_pgsql(), sip_cli_notify(), variable_clone(), vm_change_password(), and write_password_to_file().

280 {
281  struct ast_variable *variable;
282  int name_len = strlen(name) + 1;
283  int val_len = strlen(value) + 1;
284  int fn_len = strlen(filename) + 1;
285 
286  /* Ensure a minimum length in case the filename is changed later. */
287  if (fn_len < MIN_VARIABLE_FNAME_SPACE) {
288  fn_len = MIN_VARIABLE_FNAME_SPACE;
289  }
290 
291  if (
292 #ifdef MALLOC_DEBUG
293  (variable = __ast_calloc(1, fn_len + name_len + val_len + sizeof(*variable), file, lineno, func))
294 #else
295  (variable = ast_calloc(1, fn_len + name_len + val_len + sizeof(*variable)))
296 #endif
297  ) {
298  char *dst = variable->stuff; /* writable space starts here */
299 
300  /* Put file first so ast_include_rename() can calculate space available. */
301  variable->file = strcpy(dst, filename);
302  dst += fn_len;
303  variable->name = strcpy(dst, name);
304  dst += name_len;
305  variable->value = strcpy(dst, value);
306  }
307  return variable;
308 }
int lineno
Definition: config.h:87
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
void * __ast_calloc(size_t nmemb, size_t size, const char *file, int lineno, const char *func)
char stuff[0]
Contents of file, name, and value in that order stuffed here.
Definition: config.h:97
int value
Definition: syslog.c:39
const char * value
Definition: config.h:79
const char * name
Definition: config.h:77
const char * file
Definition: config.h:85
static const char name[]
#define MIN_VARIABLE_FNAME_SPACE
Definition: config.c:67
#define ast_calloc(a, b)
Definition: astmm.h:82
const char* ast_variable_retrieve ( const struct ast_config config,
const char *  category,
const char *  variable 
)

Gets a variable.

Parameters
configwhich (opened) config to use
categorycategory under which the variable lies
variablewhich variable you wish to get the data for

Goes through a given config file in the given category and searches for the given variable

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

Definition at line 625 of file config.c.

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

Referenced by __ast_udptl_reload(), __init_manager(), actual_load_config(), advanced_options(), aji_load_config(), ast_config_option(), conf_exec(), config_function_read(), config_module(), directory_exec(), do_reload(), festival_exec(), find_queue_by_name_rt(), find_realtime(), get_insecure_variable_from_config(), get_insecure_variable_from_sipregs(), gtalk_load_config(), iax_template_parse(), init_acf_query(), init_logger_chain(), initialize_cc_max_requests(), jingle_load_config(), load_config(), load_config_meetme(), load_indications(), load_module(), load_modules(), load_tech_calendars(), make_email_file(), odbc_load_module(), osp_load(), parse_config(), pbx_load_config(), pbx_load_users(), play_message(), prep_email_sub_vars(), private_enum_init(), queue_set_global_params(), read_agent_config(), read_password_from_file(), realtime_directory(), reload_config(), reload_followme(), reload_single_queue(), rtp_reload(), search_directory(), search_directory_sub(), set_config(), setup_dahdi_int(), sla_build_station(), sla_build_trunk(), sla_load_config(), tds_load_module(), update_realtime_members(), vm_change_password(), and vm_forwardoptions().

626 {
627  struct ast_variable *v;
628 
629  if (category) {
630  for (v = ast_variable_browse(config, category); v; v = v->next) {
631  if (!strcasecmp(variable, v->name)) {
632  return v->value;
633  }
634  }
635  } else {
636  struct ast_category *cat;
637 
638  for (cat = config->root; cat; cat = cat->next) {
639  for (v = cat->root; v; v = v->next) {
640  if (!strcasecmp(variable, v->name)) {
641  return v->value;
642  }
643  }
644  }
645  }
646 
647  return NULL;
648 }
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
Definition: config.c:597
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
struct ast_category * next
Definition: config.c:233
const char * value
Definition: config.h:79
struct ast_variable * root
Definition: config.c:229
const char * name
Definition: config.h:77
struct ast_category * root
Definition: config.c:238
struct ast_variable * next
Definition: config.h:82
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 942 of file config.c.

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

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

944 {
945  struct ast_variable *cur, *prev=NULL, *newer=NULL;
946 
947  for (cur = category->root; cur; prev = cur, cur = cur->next) {
948  if (strcasecmp(cur->name, variable) ||
949  (!ast_strlen_zero(match) && strcasecmp(cur->value, match)))
950  continue;
951 
952  if (!(newer = ast_variable_new(variable, value, cur->file)))
953  return -1;
954 
955  ast_variable_move(newer, cur);
956  newer->object = newer->object || object;
957 
958  /* Replace the old node in the list with the new node. */
959  newer->next = cur->next;
960  if (prev)
961  prev->next = newer;
962  else
963  category->root = newer;
964  if (category->last == cur)
965  category->last = newer;
966 
968 
969  return 0;
970  }
971 
972  /* Could not find variable to update */
973  return -1;
974 }
static void ast_variable_move(struct ast_variable *dst_var, struct ast_variable *src_var)
Definition: config.c:319
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
int object
Definition: config.h:88
struct ast_variable * last
Definition: config.c:231
int value
Definition: syslog.c:39
const char * value
Definition: config.h:79
struct ast_variable * root
Definition: config.c:229
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
const char * name
Definition: config.h:77
const char * file
Definition: config.h:85
static void ast_variable_destroy(struct ast_variable *doomed)
Definition: config.c:532
struct ast_variable * next
Definition: config.h:82
static int match(struct sockaddr_in *sin, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Definition: chan_iax2.c:2069
struct ast_variable * ast_variable_new(const char *name, const char *value, const char *filename)
Definition: config.c:278
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 586 of file config.c.

References ast_variable_destroy(), and ast_variable::next.

Referenced by __sip_destroy(), action_originate(), ast_category_destroy(), ast_category_empty(), ast_http_get_cookies(), ast_http_manid_from_vars(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_var_channel_types(), ast_var_channel_types_table(), ast_variables_dup(), auth_http_callback(), build_gateway(), build_peer(), build_user(), check_peer_ok(), cli_realtime_load(), conf_run(), copy_plain_file(), destroy_dahdi_pvt(), destroy_endpoint(), destroy_fast_originate_helper(), dup_vars(), find_conf_realtime(), 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(), handle_uri(), http_post_callback(), httpd_helper_thread(), httpstatus_callback(), ldap_loadentry(), leave_queue(), load_realtime_queue(), local_ast_moh_start(), manager_sipnotify(), mkintf(), parkandannounce_exec(), process_dahdi(), pvt_destructor(), queue_function_queuewaitingcount(), realtime_alias(), realtime_canmatch(), realtime_common(), realtime_exec(), realtime_exists(), realtime_handler(), 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(), rt_extend_conf(), sip_destroy_peer(), socket_process(), table_configs_free(), and user_destructor().

587 {
588  struct ast_variable *vn;
589 
590  while (v) {
591  vn = v;
592  v = v->next;
594  }
595 }
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
static void ast_variable_destroy(struct ast_variable *doomed)
Definition: config.c:532
struct ast_variable * next
Definition: config.h:82
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 540 of file config.c.

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

Referenced by get_insecure_variable_from_sippeers(), and get_insecure_variable_from_sipregs().

541 {
542  struct ast_variable *cloned;
543  struct ast_variable *tmp;
544 
545  if (!(cloned = ast_variable_new(var->name, var->value, var->file))) {
546  return NULL;
547  }
548 
549  tmp = cloned;
550 
551  while ((var = var->next)) {
552  if (!(tmp->next = ast_variable_new(var->name, var->value, var->file))) {
553  ast_variables_destroy(cloned);
554  return NULL;
555  }
556  tmp = tmp->next;
557  }
558 
559  return cloned;
560 }
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: config.c:586
const char * value
Definition: config.h:79
const char * name
Definition: config.h:77
const char * file
Definition: config.h:85
struct ast_variable * next
Definition: config.h:82
struct ast_variable * ast_variable_new(const char *name, const char *value, const char *filename)
Definition: config.c:278
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 562 of file config.c.

References cache_file_include::next, ast_variable::next, and var.

Referenced by astman_get_variables_order().

563 {
564  struct ast_variable *var1, *var2;
565 
566  var1 = var;
567 
568  if (!var1 || !var1->next) {
569  return var1;
570  }
571 
572  var2 = var1->next;
573  var1->next = NULL;
574 
575  while (var2) {
576  struct ast_variable *next = var2->next;
577 
578  var2->next = var1;
579  var1 = var2;
580  var2 = next;
581  }
582 
583  return var1;
584 }
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
#define var
Definition: ast_expr2f.c:606
struct ast_variable * next
Definition: config.h:82
static struct ast_category* category_get ( const struct ast_config config,
const char *  category_name,
int  ignored 
)
static

Definition at line 691 of file config.c.

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

Referenced by ast_category_get(), and process_text_line().

692 {
693  struct ast_category *cat;
694 
695  /* try exact match first, then case-insensitive match */
696  for (cat = config->root; cat; cat = cat->next) {
697  if (cat->name == category_name && (ignored || !cat->ignored))
698  return cat;
699  }
700 
701  for (cat = config->root; cat; cat = cat->next) {
702  if (!strcasecmp(cat->name, category_name) && (ignored || !cat->ignored))
703  return cat;
704  }
705 
706  return NULL;
707 }
int ignored
Definition: config.c:216
struct ast_category * next
Definition: config.c:233
char name[80]
Definition: config.c:215
struct ast_category * root
Definition: config.c:238
static void CB_ADD ( struct ast_str **  cb,
const char *  str 
)
static

Definition at line 118 of file config.c.

References ast_str_append().

Referenced by config_text_file_load().

119 {
120  ast_str_append(cb, 0, "%s", str);
121 }
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:900
const char * str
Definition: app_jack.c:144
static void CB_ADD_LEN ( struct ast_str **  cb,
const char *  str,
int  len 
)
static

Definition at line 123 of file config.c.

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

Referenced by config_text_file_load().

124 {
125  char *s = ast_alloca(len + 1);
126 
127  memcpy(s, str, len);
128  s[len] = '\0';
129  ast_str_append(cb, 0, "%s", s);
130 }
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: utils.h:653
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:900
const char * str
Definition: app_jack.c:144
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static void CB_RESET ( struct ast_str cb,
struct ast_str llb 
)
static

Definition at line 132 of file config.c.

References ast_str_reset().

Referenced by config_text_file_load(), and process_text_line().

133 {
134  if (cb) {
135  ast_str_reset(cb);
136  }
137  if (llb) {
138  ast_str_reset(llb);
139  }
140 }
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:436
static int cfmstat_cmp ( struct cache_file_mtime cfmtime,
struct stat *  statbuf 
)
static

Definition at line 1132 of file config.c.

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

1133 {
1134  struct cache_file_mtime cfm_buf;
1135 
1136  cfmstat_save(&cfm_buf, statbuf);
1137 
1138  return cfmtime->stat_size != cfm_buf.stat_size
1139  || cfmtime->stat_mtime != cfm_buf.stat_mtime
1140  || cfmtime->stat_mtime_nsec != cfm_buf.stat_mtime_nsec;
1141 }
static void cfmstat_save(struct cache_file_mtime *cfmtime, struct stat *statbuf)
Definition: config.c:1108
unsigned long stat_size
Definition: config.c:91
unsigned long stat_mtime_nsec
Definition: config.c:93
time_t stat_mtime
Definition: config.c:95
static void cfmstat_save ( struct cache_file_mtime cfmtime,
struct stat *  statbuf 
)
static

Definition at line 1108 of file config.c.

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

1109 {
1110  cfmtime->stat_size = statbuf->st_size;
1111 #if defined(HAVE_STRUCT_STAT_ST_MTIM)
1112  cfmtime->stat_mtime_nsec = statbuf->st_mtim.tv_nsec;
1113 #elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC)
1114  cfmtime->stat_mtime_nsec = statbuf->st_mtimensec;
1115 #elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC)
1116  cfmtime->stat_mtime_nsec = statbuf->st_mtimespec.tv_nsec;
1117 #else
1118  cfmtime->stat_mtime_nsec = 0;
1119 #endif
1120  cfmtime->stat_mtime = statbuf->st_mtime;
1121 }
unsigned long stat_size
Definition: config.c:91
unsigned long stat_mtime_nsec
Definition: config.c:93
time_t stat_mtime
Definition: config.c:95
static struct cache_file_mtime* cfmtime_new ( const char *  filename,
const char *  who_asked 
)
static

Definition at line 1076 of file config.c.

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

Referenced by config_cache_attribute(), and config_text_file_load().

1077 {
1078  struct cache_file_mtime *cfmtime;
1079  char *dst;
1080 
1081  cfmtime = ast_calloc(1,
1082  sizeof(*cfmtime) + strlen(filename) + 1 + strlen(who_asked) + 1);
1083  if (!cfmtime) {
1084  return NULL;
1085  }
1086  dst = cfmtime->filename; /* writable space starts here */
1087  strcpy(dst, filename); /* Safe */
1088  dst += strlen(dst) + 1;
1089  cfmtime->who_asked = strcpy(dst, who_asked); /* Safe */
1090 
1091  return cfmtime;
1092 }
const char * who_asked
Definition: config.c:98
char filename[0]
Definition: config.c:100
#define ast_calloc(a, b)
Definition: astmm.h:82
static void clear_config_maps ( void  )
static

Definition at line 2248 of file config.c.

References ast_free, ast_mutex_lock, ast_mutex_unlock, config_lock, config_maps, map, and ast_config_map::next.

Referenced by read_config_maps().

2249 {
2250  struct ast_config_map *map;
2251 
2253 
2254  while (config_maps) {
2255  map = config_maps;
2257  ast_free(map);
2258  }
2259 
2261 }
static ast_mutex_t config_lock
Definition: config.c:203
static int * map
Definition: misdn_config.c:434
#define ast_mutex_lock(a)
Definition: lock.h:155
static struct ast_config_map * config_maps
#define ast_free(a)
Definition: astmm.h:97
struct ast_config_map * next
Definition: config.c:189
#define ast_mutex_unlock(a)
Definition: lock.h:156
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 1204 of file config.c.

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

1205 {
1206  struct cache_file_mtime *cfmtime;
1207  struct cache_file_include *cfinclude;
1208 
1209  /* Find our cached entry for this configuration file */
1211  AST_LIST_TRAVERSE(&cfmtime_head, cfmtime, list) {
1212  if (!strcmp(cfmtime->filename, configfile) && !strcmp(cfmtime->who_asked, who_asked))
1213  break;
1214  }
1215  if (!cfmtime) {
1216  cfmtime = cfmtime_new(configfile, who_asked);
1217  if (!cfmtime) {
1219  return;
1220  }
1221  /* Note that the file mtime is initialized to 0, i.e. 1970 */
1222  AST_LIST_INSERT_SORTALPHA(&cfmtime_head, cfmtime, list, filename);
1223  }
1224 
1225  switch (attrtype) {
1226  case ATTRIBUTE_INCLUDE:
1227  AST_LIST_TRAVERSE(&cfmtime->includes, cfinclude, list) {
1228  if (!strcmp(cfinclude->include, filename)) {
1230  return;
1231  }
1232  }
1233  cfinclude = ast_calloc(1, sizeof(*cfinclude) + strlen(filename) + 1);
1234  if (!cfinclude) {
1236  return;
1237  }
1238  strcpy(cfinclude->include, filename); /* Safe */
1239  AST_LIST_INSERT_TAIL(&cfmtime->includes, cfinclude, list);
1240  break;
1241  case ATTRIBUTE_EXEC:
1242  cfmtime->has_exec = 1;
1243  break;
1244  }
1246 }
unsigned int has_exec
Definition: config.c:89
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
static struct cache_file_mtime * cfmtime_new(const char *filename, const char *who_asked)
Definition: config.c:1076
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
char include[0]
Definition: config.c:83
Hold the mtime for config files, so if we don&#39;t need to reread our config, don&#39;t. ...
Definition: config.c:80
#define AST_LIST_INSERT_SORTALPHA(head, elm, field, sortfield)
Inserts a list entry into a alphabetically sorted list.
Definition: linkedlists.h:736
const char * who_asked
Definition: config.c:98
char filename[0]
Definition: config.c:100
struct cache_file_mtime::includes includes
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:716
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define ast_calloc(a, b)
Definition: astmm.h:82
struct cache_file_include::@241 list
static void config_cache_destroy_entry ( struct cache_file_mtime cfmtime)
static

Definition at line 1172 of file config.c.

References ast_free, and config_cache_flush_includes().

Referenced by config_cache_remove(), and config_shutdown().

1173 {
1174  config_cache_flush_includes(cfmtime);
1175  ast_free(cfmtime);
1176 }
static void config_cache_flush_includes(struct cache_file_mtime *cfmtime)
Definition: config.c:1153
#define ast_free(a)
Definition: astmm.h:97
static void config_cache_flush_includes ( struct cache_file_mtime cfmtime)
static

Definition at line 1153 of file config.c.

References ast_free, AST_LIST_REMOVE_HEAD, and cache_file_mtime::includes.

Referenced by config_cache_destroy_entry(), and config_text_file_load().

1154 {
1155  struct cache_file_include *cfinclude;
1156 
1157  while ((cfinclude = AST_LIST_REMOVE_HEAD(&cfmtime->includes, list))) {
1158  ast_free(cfinclude);
1159  }
1160 }
Hold the mtime for config files, so if we don&#39;t need to reread our config, don&#39;t. ...
Definition: config.c:80
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:818
struct cache_file_mtime::includes includes
#define ast_free(a)
Definition: astmm.h:97
struct cache_file_include::@241 list
static void config_cache_remove ( const char *  filename,
const char *  who_asked 
)
static

Definition at line 1187 of file config.c.

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

1188 {
1189  struct cache_file_mtime *cfmtime;
1190 
1193  if (!strcmp(cfmtime->filename, filename)
1194  && !strcmp(cfmtime->who_asked, who_asked)) {
1196  config_cache_destroy_entry(cfmtime);
1197  break;
1198  }
1199  }
1202 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:600
static void config_cache_destroy_entry(struct cache_file_mtime *cfmtime)
Definition: config.c:1172
const char * who_asked
Definition: config.c:98
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:554
char filename[0]
Definition: config.c:100
struct cache_file_mtime::@242 list
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
static void config_shutdown ( void  )
static

Definition at line 3132 of file config.c.

References ARRAY_LEN, ast_cli_unregister_multiple(), AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, and config_cache_destroy_entry().

Referenced by register_config_cli().

3133 {
3134  struct cache_file_mtime *cfmtime;
3135 
3137  while ((cfmtime = AST_LIST_REMOVE_HEAD(&cfmtime_head, list))) {
3138  config_cache_destroy_entry(cfmtime);
3139  }
3141 
3143 }
static struct ast_cli_entry cli_config[]
Definition: config.c:3126
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: cli.c:2177
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
static void config_cache_destroy_entry(struct cache_file_mtime *cfmtime)
Definition: config.c:1172
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:818
struct cache_file_mtime::@242 list
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 1503 of file config.c.

References ALLOC_COMMENT(), ast_clear_flag, ast_config_AST_CONFIG_DIR, ast_config_get_current_category(), ast_copy_string(), ast_debug, ast_free, AST_LIST_INSERT_SORTALPHA, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_str_buffer(), ast_str_create(), ast_str_reset(), ast_str_strlen(), ast_strip(), ast_strlen_zero(), ast_test_flag, ast_verb, CB_ADD(), CB_ADD_LEN(), CB_RESET(), CB_SIZE, cfmstat_cmp(), cfmstat_save(), cfmtime_new(), comment, COMMENT_META, COMMENT_TAG, config_cache_flush_includes(), config_cache_remove(), CONFIG_FLAG_FILEUNCHANGED, CONFIG_FLAG_NOCACHE, CONFIG_FLAG_WITHCOMMENTS, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, errno, f, cache_file_mtime::filename, GLOB_ABORTED, cache_file_mtime::has_exec, cache_file_include::include, cache_file_mtime::includes, LOG_ERROR, LOG_WARNING, MAX_NESTED_COMMENTS, MY_GLOB_FLAGS, process_text_line(), ast_variable::trailing, ast_category::trailing, and cache_file_mtime::who_asked.

1504 {
1505  char fn[256];
1506 #if defined(LOW_MEMORY)
1507  char buf[512];
1508 #else
1509  char buf[8192];
1510 #endif
1511  char *new_buf, *comment_p, *process_buf;
1512  FILE *f;
1513  int lineno=0;
1514  int comment = 0, nest[MAX_NESTED_COMMENTS];
1515  struct ast_category *cat = NULL;
1516  int count = 0;
1517  struct stat statbuf;
1518  struct cache_file_mtime *cfmtime = NULL;
1519  struct cache_file_include *cfinclude;
1520  struct ast_variable *last_var = 0;
1521  struct ast_category *last_cat = 0;
1522  /*! Growable string buffer */
1523  struct ast_str *comment_buffer = NULL; /*!< this will be a comment collector.*/
1524  struct ast_str *lline_buffer = NULL; /*!< A buffer for stuff behind the ; */
1525 
1526  if (cfg)
1528 
1529  if (filename[0] == '/') {
1530  ast_copy_string(fn, filename, sizeof(fn));
1531  } else {
1532  snprintf(fn, sizeof(fn), "%s/%s", ast_config_AST_CONFIG_DIR, filename);
1533  }
1534 
1535  if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)) {
1536  comment_buffer = ast_str_create(CB_SIZE);
1537  if (comment_buffer)
1538  lline_buffer = ast_str_create(CB_SIZE);
1539  if (!lline_buffer) {
1540  ast_free(comment_buffer);
1541  ast_log(LOG_ERROR, "Failed to initialize the comment buffer!\n");
1542  return NULL;
1543  }
1544  }
1545 #ifdef AST_INCLUDE_GLOB
1546  {
1547  int glob_ret;
1548  glob_t globbuf;
1549 
1550  globbuf.gl_offs = 0; /* initialize it to silence gcc */
1551  glob_ret = glob(fn, MY_GLOB_FLAGS, NULL, &globbuf);
1552  if (glob_ret == GLOB_NOSPACE) {
1554  "Glob Expansion of pattern '%s' failed: Not enough memory\n", fn);
1555  } else if (glob_ret == GLOB_ABORTED) {
1557  "Glob Expansion of pattern '%s' failed: Read error\n", fn);
1558  } else {
1559  /* loop over expanded files */
1560  int i;
1561 
1562  if (!cfg && (globbuf.gl_pathc != 1 || strcmp(fn, globbuf.gl_pathv[0]))) {
1563  /*
1564  * We just want a file changed answer and since we cannot
1565  * tell if a file was deleted with wildcard matching we will
1566  * assume that something has always changed. Also without
1567  * a lot of refactoring we couldn't check more than one file
1568  * for changes in the glob loop anyway.
1569  */
1570  globfree(&globbuf);
1571  ast_free(comment_buffer);
1572  ast_free(lline_buffer);
1573  return NULL;
1574  }
1575  for (i=0; i<globbuf.gl_pathc; i++) {
1576  ast_copy_string(fn, globbuf.gl_pathv[i], sizeof(fn));
1577 #endif
1578  /*
1579  * The following is not a loop, but just a convenient way to define a block
1580  * (using do { } while(0) ), and be able to exit from it with 'continue'
1581  * or 'break' in case of errors. Nice trick.
1582  */
1583  do {
1584  if (stat(fn, &statbuf)) {
1585  if (!ast_test_flag(&flags, CONFIG_FLAG_NOCACHE)) {
1586  config_cache_remove(fn, who_asked);
1587  }
1588  continue;
1589  }
1590 
1591  if (!S_ISREG(statbuf.st_mode)) {
1592  ast_log(LOG_WARNING, "'%s' is not a regular file, ignoring\n", fn);
1593  if (!ast_test_flag(&flags, CONFIG_FLAG_NOCACHE)) {
1594  config_cache_remove(fn, who_asked);
1595  }
1596  continue;
1597  }
1598 
1599  if (!ast_test_flag(&flags, CONFIG_FLAG_NOCACHE)) {
1600  /* Find our cached entry for this configuration file */
1602  AST_LIST_TRAVERSE(&cfmtime_head, cfmtime, list) {
1603  if (!strcmp(cfmtime->filename, fn) && !strcmp(cfmtime->who_asked, who_asked))
1604  break;
1605  }
1606  if (!cfmtime) {
1607  cfmtime = cfmtime_new(fn, who_asked);
1608  if (!cfmtime) {
1610  continue;
1611  }
1612  /* Note that the file mtime is initialized to 0, i.e. 1970 */
1613  AST_LIST_INSERT_SORTALPHA(&cfmtime_head, cfmtime, list, filename);
1614  }
1615  }
1616 
1617  if (cfmtime
1618  && !cfmtime->has_exec
1619  && !cfmstat_cmp(cfmtime, &statbuf)
1621  int unchanged = 1;
1622 
1623  /* File is unchanged, what about the (cached) includes (if any)? */
1624  AST_LIST_TRAVERSE(&cfmtime->includes, cfinclude, list) {
1625  if (!config_text_file_load(NULL, NULL, cfinclude->include,
1626  NULL, flags, "", who_asked)) {
1627  /* One change is enough to short-circuit and reload the whole shebang */
1628  unchanged = 0;
1629  break;
1630  }
1631  }
1632 
1633  if (unchanged) {
1635 #ifdef AST_INCLUDE_GLOB
1636  globfree(&globbuf);
1637 #endif
1638  ast_free(comment_buffer);
1639  ast_free(lline_buffer);
1641  }
1642  }
1643 
1644  /* If cfg is NULL, then we just want a file changed answer. */
1645  if (cfg == NULL) {
1646  if (cfmtime) {
1648  }
1649  continue;
1650  }
1651 
1652  if (cfmtime) {
1653  /* Forget about what we thought we knew about this file's includes. */
1654  cfmtime->has_exec = 0;
1655  config_cache_flush_includes(cfmtime);
1656 
1657  cfmstat_save(cfmtime, &statbuf);
1659  }
1660 
1661  ast_verb(2, "Parsing '%s': ", fn);
1662  fflush(stdout);
1663  if (!(f = fopen(fn, "r"))) {
1664  ast_debug(1, "No file to parse: %s\n", fn);
1665  ast_verb(2, "Not found (%s)\n", strerror(errno));
1666  continue;
1667  }
1668  count++;
1669  /* If we get to this point, then we're loading regardless */
1671  ast_debug(1, "Parsing %s\n", fn);
1672  ast_verb(2, "Found\n");
1673  while (!feof(f)) {
1674  lineno++;
1675  if (fgets(buf, sizeof(buf), f)) {
1676  /* Skip lines that are too long */
1677  if (strlen(buf) == sizeof(buf) - 1 && buf[sizeof(buf) - 1] != '\n') {
1678  ast_log(LOG_WARNING, "Line %d too long, skipping. It begins with: %.32s...\n", lineno, buf);
1679  while (fgets(buf, sizeof(buf), f)) {
1680  if (strlen(buf) != sizeof(buf) - 1 || buf[sizeof(buf) - 1] == '\n') {
1681  break;
1682  }
1683  }
1684  continue;
1685  }
1686 
1687  if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && lline_buffer && ast_str_strlen(lline_buffer)) {
1688  CB_ADD(&comment_buffer, ast_str_buffer(lline_buffer)); /* add the current lline buffer to the comment buffer */
1689  ast_str_reset(lline_buffer); /* erase the lline buffer */
1690  }
1691 
1692  new_buf = buf;
1693  if (comment)
1694  process_buf = NULL;
1695  else
1696  process_buf = buf;
1697 
1698  if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && comment_buffer && ast_str_strlen(comment_buffer) && (ast_strlen_zero(buf) || strlen(buf) == strspn(buf," \t\n\r"))) {
1699  /* blank line? really? Can we add it to an existing comment and maybe preserve inter- and post- comment spacing? */
1700  CB_ADD(&comment_buffer, "\n"); /* add a newline to the comment buffer */
1701  continue; /* go get a new line, then */
1702  }
1703 
1704  while ((comment_p = strchr(new_buf, COMMENT_META))) {
1705  if ((comment_p > new_buf) && (*(comment_p - 1) == '\\')) {
1706  /* Escaped semicolons aren't comments. */
1707  new_buf = comment_p;
1708  /* write over the \ and bring the null terminator with us */
1709  memmove(comment_p - 1, comment_p, strlen(comment_p) + 1);
1710  } else if (comment_p[1] == COMMENT_TAG && comment_p[2] == COMMENT_TAG && (comment_p[3] != '-')) {
1711  /* Meta-Comment start detected ";--" */
1712  if (comment < MAX_NESTED_COMMENTS) {
1713  *comment_p = '\0';
1714  new_buf = comment_p + 3;
1715  comment++;
1716  nest[comment-1] = lineno;
1717  } else {
1718  ast_log(LOG_ERROR, "Maximum nest limit of %d reached.\n", MAX_NESTED_COMMENTS);
1719  }
1720  } else if ((comment_p >= new_buf + 2) &&
1721  (*(comment_p - 1) == COMMENT_TAG) &&
1722  (*(comment_p - 2) == COMMENT_TAG)) {
1723  /* Meta-Comment end detected "--;" */
1724  comment--;
1725  new_buf = comment_p + 1;
1726  if (!comment) {
1727  /* Back to non-comment now */
1728  if (process_buf) {
1729  /* Actually have to move what's left over the top, then continue */
1730  char *oldptr;
1731  oldptr = process_buf + strlen(process_buf);
1732  if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)) {
1733  CB_ADD(&comment_buffer, ";");
1734  CB_ADD_LEN(&comment_buffer, oldptr+1, new_buf-oldptr-1);
1735  }
1736 
1737  memmove(oldptr, new_buf, strlen(new_buf) + 1);
1738  new_buf = oldptr;
1739  } else
1740  process_buf = new_buf;
1741  }
1742  } else {
1743  if (!comment) {
1744  /* If ; is found, and we are not nested in a comment,
1745  we immediately stop all comment processing */
1746  if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS)) {
1747  CB_ADD(&lline_buffer, comment_p);
1748  }
1749  *comment_p = '\0';
1750  new_buf = comment_p;
1751  } else
1752  new_buf = comment_p + 1;
1753  }
1754  }
1755  if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && comment && !process_buf ) {
1756  CB_ADD(&comment_buffer, buf); /* the whole line is a comment, store it */
1757  }
1758 
1759  if (process_buf) {
1760  char *buffer = ast_strip(process_buf);
1761  if (!ast_strlen_zero(buffer)) {
1762  if (process_text_line(cfg, &cat, buffer, lineno, fn, flags, comment_buffer, lline_buffer, suggested_include_file, &last_cat, &last_var, who_asked)) {
1764  break;
1765  }
1766  }
1767  }
1768  }
1769  }
1770  /* end of file-- anything in a comment buffer? */
1771  if (last_cat) {
1772  if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && comment_buffer && ast_str_strlen(comment_buffer)) {
1773  if (lline_buffer && ast_str_strlen(lline_buffer)) {
1774  CB_ADD(&comment_buffer, ast_str_buffer(lline_buffer)); /* add the current lline buffer to the comment buffer */
1775  ast_str_reset(lline_buffer); /* erase the lline buffer */
1776  }
1777  last_cat->trailing = ALLOC_COMMENT(comment_buffer);
1778  }
1779  } else if (last_var) {
1780  if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && comment_buffer && ast_str_strlen(comment_buffer)) {
1781  if (lline_buffer && ast_str_strlen(lline_buffer)) {
1782  CB_ADD(&comment_buffer, ast_str_buffer(lline_buffer)); /* add the current lline buffer to the comment buffer */
1783  ast_str_reset(lline_buffer); /* erase the lline buffer */
1784  }
1785  last_var->trailing = ALLOC_COMMENT(comment_buffer);
1786  }
1787  } else {
1788  if (ast_test_flag(&flags, CONFIG_FLAG_WITHCOMMENTS) && comment_buffer && ast_str_strlen(comment_buffer)) {
1789  ast_debug(1, "Nothing to attach comments to, discarded: %s\n", ast_str_buffer(comment_buffer));
1790  }
1791  }
1793  CB_RESET(comment_buffer, lline_buffer);
1794 
1795  fclose(f);
1796  } while (0);
1797  if (comment) {
1798  ast_log(LOG_WARNING,"Unterminated comment detected beginning on line %d\n", nest[comment - 1]);
1799  }
1800 #ifdef AST_INCLUDE_GLOB
1801  if (cfg == NULL || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
1802  break;
1803  }
1804  }
1805  globfree(&globbuf);
1806  }
1807  }
1808 #endif
1809 
1810  ast_free(comment_buffer);
1811  ast_free(lline_buffer);
1812 
1813  if (count == 0)
1814  return NULL;
1815 
1816  return cfg;
1817 }
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.
Definition: config.c:1255
unsigned int has_exec
Definition: config.c:89
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
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)
Definition: config.c:1503
static struct cache_file_mtime * cfmtime_new(const char *filename, const char *who_asked)
Definition: config.c:1076
#define ast_test_flag(p, flag)
Definition: utils.h:63
static void CB_ADD_LEN(struct ast_str **cb, const char *str, int len)
Definition: config.c:123
#define LOG_WARNING
Definition: logger.h:144
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:497
struct ast_category * ast_config_get_current_category(const struct ast_config *cfg)
Retrieve the current category name being built.
Definition: config.c:1055
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
static void config_cache_flush_includes(struct cache_file_mtime *cfmtime)
Definition: config.c:1153
struct ast_str * ast_str_create(size_t init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:420
char include[0]
Definition: config.c:83
#define ast_verb(level,...)
Definition: logger.h:243
Hold the mtime for config files, so if we don&#39;t need to reread our config, don&#39;t. ...
Definition: config.c:80
#define AST_LIST_INSERT_SORTALPHA(head, elm, field, sortfield)
Inserts a list entry into a alphabetically sorted list.
Definition: linkedlists.h:736
struct ast_comment * trailing
Definition: config.h:92
const char * who_asked
Definition: config.c:98
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
struct ast_comment * trailing
Definition: config.c:227
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define MAX_NESTED_COMMENTS
Definition: config.c:56
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:155
static void CB_RESET(struct ast_str *cb, struct ast_str *llb)
Definition: config.c:132
static void config_cache_remove(const char *filename, const char *who_asked)
Definition: config.c:1187
char filename[0]
Definition: config.c:100
static void cfmstat_save(struct cache_file_mtime *cfmtime, struct stat *statbuf)
Definition: config.c:1108
struct cache_file_mtime::includes includes
#define LOG_ERROR
Definition: logger.h:155
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:364
static void CB_ADD(struct ast_str **cb, const char *str)
Definition: config.c:118
const char * ast_config_AST_CONFIG_DIR
Definition: asterisk.c:256
static int cfmstat_cmp(struct cache_file_mtime *cfmtime, struct stat *statbuf)
Definition: config.c:1132
#define comment
Definition: ael_lex.c:961
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define CB_SIZE
Definition: config.c:116
#define MY_GLOB_FLAGS
Definition: compat.h:214
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
int errno
#define ast_free(a)
Definition: astmm.h:97
#define GLOB_ABORTED
Definition: ael_lex.c:830
static struct ast_comment * ALLOC_COMMENT(struct ast_str *buffer)
Definition: config.c:142
static struct ast_format f[]
Definition: format_g726.c:181
#define ast_clear_flag(p, flag)
Definition: utils.h:77
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:436
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:471
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
#define COMMENT_META
Definition: config.c:59
#define CONFIG_STATUS_FILEINVALID
Definition: config.h:52
#define COMMENT_TAG
Definition: config.c:60
#define CONFIG_STATUS_FILEUNCHANGED
Definition: config.h:51
int config_text_file_save ( const char *  configfile,
const struct ast_config cfg,
const char *  generator 
)

Definition at line 1972 of file config.c.

References ast_config_text_file_save().

1973 {
1974  return ast_config_text_file_save(configfile, cfg, generator);
1975 }
int ast_config_text_file_save(const char *filename, const struct ast_config *cfg, const char *generator)
Definition: config.c:1977
static struct ast_generator generator
Definition: app_fax.c:361
static int count_linefeeds ( char *  str)
static

Definition at line 1913 of file config.c.

Referenced by count_linefeeds_in_comments().

1914 {
1915  int count = 0;
1916 
1917  while (*str) {
1918  if (*str =='\n')
1919  count++;
1920  str++;
1921  }
1922  return count;
1923 }
const char * str
Definition: app_jack.c:144
static int count_linefeeds_in_comments ( struct ast_comment x)
static

Definition at line 1925 of file config.c.

References ast_comment::cmt, count_linefeeds(), and ast_comment::next.

Referenced by insert_leading_blank_lines().

1926 {
1927  int count = 0;
1928 
1929  while (x) {
1930  count += count_linefeeds(x->cmt);
1931  x = x->next;
1932  }
1933  return count;
1934 }
char cmt[0]
Definition: config.c:76
struct ast_comment * next
Definition: config.c:74
static int count_linefeeds(char *str)
Definition: config.c:1913
static struct ast_config_engine* find_engine ( const char *  family,
int  priority,
char *  database,
int  dbsiz,
char *  table,
int  tabsiz 
)
static

Find realtime engine for realtime family.

Definition at line 2420 of file config.c.

References ast_copy_string(), ast_log(), ast_mutex_lock, ast_mutex_unlock, config_lock, config_maps, ast_config_map::database, ast_config_map::driver, LOG_WARNING, map, ast_config_map::name, ast_config_engine::next, ast_config_map::next, ast_config_map::priority, and ast_config_map::table.

Referenced by ast_check_realtime(), ast_config_internal_load(), ast_destroy_realtime(), ast_load_realtime_helper(), ast_load_realtime_multientry(), ast_realtime_require_field(), ast_store_realtime(), ast_unload_realtime(), ast_update2_realtime(), and ast_update_realtime().

2421 {
2422  struct ast_config_engine *eng, *ret = NULL;
2423  struct ast_config_map *map;
2424 
2426 
2427  for (map = config_maps; map; map = map->next) {
2428  if (!strcasecmp(family, map->name) && (priority == map->priority)) {
2429  if (database)
2430  ast_copy_string(database, map->database, dbsiz);
2431  if (table)
2432  ast_copy_string(table, map->table ? map->table : family, tabsiz);
2433  break;
2434  }
2435  }
2436 
2437  /* Check if the required driver (engine) exist */
2438  if (map) {
2439  for (eng = config_engine_list; !ret && eng; eng = eng->next) {
2440  if (!strcasecmp(eng->name, map->driver))
2441  ret = eng;
2442  }
2443  }
2444 
2446 
2447  /* if we found a mapping, but the engine is not available, then issue a warning */
2448  if (map && !ret)
2449  ast_log(LOG_WARNING, "Realtime mapping for '%s' found to engine '%s', but the engine is not available\n", map->name, map->driver);
2450 
2451  return ret;
2452 }
struct ast_config_engine * next
Definition: config.h:132
static ast_mutex_t config_lock
Definition: config.c:203
static int * map
Definition: misdn_config.c:434
#define LOG_WARNING
Definition: logger.h:144
const char * database
Definition: config.c:196
#define ast_mutex_lock(a)
Definition: lock.h:155
const char * table
Definition: config.c:198
Configuration engine structure, used to define realtime drivers.
Definition: config.h:121
static struct ast_config_map * config_maps
static char * table
Definition: cdr_odbc.c:50
int priority
Definition: config.c:190
const char * name
Definition: config.c:192
static struct ast_config_engine * config_engine_list
Definition: config.c:204
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
const char * driver
Definition: config.c:194
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
struct ast_config_map * next
Definition: config.c:189
#define ast_mutex_unlock(a)
Definition: lock.h:156
static void gen_header ( FILE *  f1,
const char *  configfile,
const char *  fn,
const char *  generator 
)
static

Definition at line 1840 of file config.c.

References ast_copy_string().

Referenced by ast_config_text_file_save().

1841 {
1842  char date[256]="";
1843  time_t t;
1844 
1845  time(&t);
1846  ast_copy_string(date, ctime(&t), sizeof(date));
1847 
1848  fprintf(f1, ";!\n");
1849  fprintf(f1, ";! Automatically generated configuration file\n");
1850  if (strcmp(configfile, fn))
1851  fprintf(f1, ";! Filename: %s (%s)\n", configfile, fn);
1852  else
1853  fprintf(f1, ";! Filename: %s\n", configfile);
1854  fprintf(f1, ";! Generator: %s\n", generator);
1855  fprintf(f1, ";! Creation Date: %s", date);
1856  fprintf(f1, ";!\n");
1857 }
static struct ast_generator generator
Definition: app_fax.c:361
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
static char* handle_cli_config_list ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 3102 of file config.c.

References ast_cli(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, cache_file_mtime::filename, S_OR, ast_cli_entry::usage, and cache_file_mtime::who_asked.

3103 {
3104  struct cache_file_mtime *cfmtime;
3105 
3106  switch (cmd) {
3107  case CLI_INIT:
3108  e->command = "config list";
3109  e->usage =
3110  "Usage: config list\n"
3111  " Show all modules that have loaded a configuration file\n";
3112  return NULL;
3113  case CLI_GENERATE:
3114  return NULL;
3115  }
3116 
3118  AST_LIST_TRAVERSE(&cfmtime_head, cfmtime, list) {
3119  ast_cli(a->fd, "%-20.20s %-50s\n", S_OR(cfmtime->who_asked, "core"), cfmtime->filename);
3120  }
3122 
3123  return CLI_SUCCESS;
3124 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
Definition: cli.h:146
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
const char * who_asked
Definition: config.c:98
const int fd
Definition: cli.h:153
char filename[0]
Definition: config.c:100
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
char * command
Definition: cli.h:180
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
struct cache_file_mtime::@242 list
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:77
static char* handle_cli_config_reload ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 3040 of file config.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_alloca, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_strdup, ast_strlen_zero(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, cache_file_mtime::filename, ast_cli_args::n, ast_cli_args::pos, ast_cli_entry::usage, cache_file_mtime::who_asked, and ast_cli_args::word.

3041 {
3042  struct cache_file_mtime *cfmtime;
3043  char *prev = "", *completion_value = NULL;
3044  int wordlen, which = 0;
3045 
3046  switch (cmd) {
3047  case CLI_INIT:
3048  e->command = "config reload";
3049  e->usage =
3050  "Usage: config reload <filename.conf>\n"
3051  " Reloads all modules that reference <filename.conf>\n";
3052  return NULL;
3053  case CLI_GENERATE:
3054  if (a->pos > 2) {
3055  return NULL;
3056  }
3057 
3058  wordlen = strlen(a->word);
3059 
3061  AST_LIST_TRAVERSE(&cfmtime_head, cfmtime, list) {
3062  /* Skip duplicates - this only works because the list is sorted by filename */
3063  if (strcmp(cfmtime->filename, prev) == 0) {
3064  continue;
3065  }
3066 
3067  /* Core configs cannot be reloaded */
3068  if (ast_strlen_zero(cfmtime->who_asked)) {
3069  continue;
3070  }
3071 
3072  if (++which > a->n && strncmp(cfmtime->filename, a->word, wordlen) == 0) {
3073  completion_value = ast_strdup(cfmtime->filename);
3074  break;
3075  }
3076 
3077  /* Otherwise save that we've seen this filename */
3078  prev = cfmtime->filename;
3079  }
3081 
3082  return completion_value;
3083  }
3084 
3085  if (a->argc != 3) {
3086  return CLI_SHOWUSAGE;
3087  }
3088 
3090  AST_LIST_TRAVERSE(&cfmtime_head, cfmtime, list) {
3091  if (!strcmp(cfmtime->filename, a->argv[2])) {
3092  char *buf = ast_alloca(strlen("module reload ") + strlen(cfmtime->who_asked) + 1);
3093  sprintf(buf, "module reload %s", cfmtime->who_asked);
3094  ast_cli_command(a->fd, buf);
3095  }
3096  }
3098 
3099  return CLI_SUCCESS;
3100 }
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
#define ast_strdup(a)
Definition: astmm.h:109
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: utils.h:653
const int argc
Definition: cli.h:154
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
Definition: cli.h:146
const char * who_asked
Definition: config.c:98
const int fd
Definition: cli.h:153
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
const int n
Definition: cli.h:159
ast_cli_command
calling arguments for new-style handlers.
Definition: cli.h:145
char filename[0]
Definition: config.c:100
const char *const * argv
Definition: cli.h:155
#define CLI_SHOWUSAGE
Definition: cli.h:44
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
char * command
Definition: cli.h:180
const char * word
Definition: cli.h:157
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
struct cache_file_mtime::@242 list
const int pos
Definition: cli.h:158
static char* handle_cli_core_show_config_mappings ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 3003 of file config.c.

References ast_cli(), ast_mutex_lock, ast_mutex_unlock, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, config_lock, config_maps, ast_config_map::database, ast_config_map::driver, ast_cli_args::fd, map, ast_config_engine::name, ast_config_map::name, ast_config_engine::next, ast_config_map::next, ast_config_map::table, and ast_cli_entry::usage.

3004 {
3005  struct ast_config_engine *eng;
3006  struct ast_config_map *map;
3007 
3008  switch (cmd) {
3009  case CLI_INIT:
3010  e->command = "core show config mappings";
3011  e->usage =
3012  "Usage: core show config mappings\n"
3013  " Shows the filenames to config engines.\n";
3014  return NULL;
3015  case CLI_GENERATE:
3016  return NULL;
3017  }
3018 
3020 
3021  if (!config_engine_list) {
3022  ast_cli(a->fd, "No config mappings found.\n");
3023  } else {
3024  for (eng = config_engine_list; eng; eng = eng->next) {
3025  ast_cli(a->fd, "Config Engine: %s\n", eng->name);
3026  for (map = config_maps; map; map = map->next) {
3027  if (!strcasecmp(map->driver, eng->name)) {
3028  ast_cli(a->fd, "===> %s (db=%s, table=%s)\n", map->name, map->database,
3029  map->table ? map->table : map->name);
3030  }
3031  }
3032  }
3033  }
3034 
3036 
3037  return CLI_SUCCESS;
3038 }
struct ast_config_engine * next
Definition: config.h:132
static ast_mutex_t config_lock
Definition: config.c:203
static int * map
Definition: misdn_config.c:434
const char * database
Definition: config.c:196
Definition: cli.h:146
#define ast_mutex_lock(a)
Definition: lock.h:155
const char * table
Definition: config.c:198
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
Configuration engine structure, used to define realtime drivers.
Definition: config.h:121
static struct ast_config_map * config_maps
const int fd
Definition: cli.h:153
const char * name
Definition: config.c:192
static struct ast_config_engine * config_engine_list
Definition: config.c:204
char * command
Definition: cli.h:180
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
const char * driver
Definition: config.c:194
struct ast_config_map * next
Definition: config.c:189
#define ast_mutex_unlock(a)
Definition: lock.h:156
static int hash_string ( const void *  obj,
const int  flags 
)
static

Definition at line 162 of file config.c.

References str, and total.

Referenced by ast_config_text_file_save().

163 {
164  char *str = ((struct inclfile *) obj)->fname;
165  int total;
166 
167  for (total = 0; *str; str++) {
168  unsigned int tmp = total;
169  total <<= 1; /* multiply by 2 */
170  total += tmp; /* multiply by 3 */
171  total <<= 2; /* multiply by 12 */
172  total += tmp; /* multiply by 13 */
173 
174  total += ((unsigned int) (*str));
175  }
176  if (total < 0) {
177  total = -total;
178  }
179  return total;
180 }
const char * str
Definition: app_jack.c:144
static int total
Definition: res_adsi.c:967
static int hashtab_compare_strings ( void *  a,
void *  b,
int  flags 
)
static

Definition at line 182 of file config.c.

References CMP_MATCH, CMP_STOP, and inclfile::fname.

Referenced by ast_config_text_file_save().

183 {
184  const struct inclfile *ae = a, *be = b;
185  return !strcmp(ae->fname, be->fname) ? CMP_MATCH | CMP_STOP : 0;
186 }
char * fname
Definition: config.c:158
static void inclfile_destroy ( void *  obj)
static

Definition at line 1859 of file config.c.

References ast_free, and inclfile::fname.

Referenced by set_fn().

1860 {
1861  const struct inclfile *o = obj;
1862 
1863  ast_free(o->fname);
1864 }
#define ast_free(a)
Definition: astmm.h:97
char * fname
Definition: config.c:158
static void inherit_category ( struct ast_category new,
const struct ast_category base 
)
static

Definition at line 872 of file config.c.

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

Referenced by process_text_line().

873 {
874  struct ast_variable *var;
876 
877  x = ast_calloc(1, sizeof(*x));
878  if (!x) {
879  return;
880  }
881  strcpy(x->name, base->name);
882  x->inst = base;
884  for (var = base->root; var; var = var->next)
886 }
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
#define var
Definition: ast_expr2f.c:606
static struct ast_variable * variable_clone(const struct ast_variable *old)
Definition: config.c:650
char name[80]
Definition: config.c:215
struct ast_category::template_instance_list template_instances
struct ast_variable * root
Definition: config.c:229
struct ast_category_template_instance * next
Definition: config.c:211
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:716
void ast_variable_append(struct ast_category *category, struct ast_variable *variable)
Definition: config.c:483
#define ast_calloc(a, b)
Definition: astmm.h:82
struct ast_variable * next
Definition: config.h:82
struct ast_category * inst
Definition: config.c:210
static int init_appendbuf ( void *  data)
static

Definition at line 106 of file config.c.

References ast_str_create(), and str.

107 {
108  struct ast_str **str = data;
109  *str = ast_str_create(16);
110  return *str ? 0 : -1;
111 }
struct ast_str * ast_str_create(size_t init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:420
const char * str
Definition: app_jack.c:144
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:364
static void insert_leading_blank_lines ( FILE *  fp,
struct inclfile fi,
struct ast_comment precomments,
int  lineno 
)
static

Definition at line 1936 of file config.c.

References count_linefeeds_in_comments(), and inclfile::lineno.

Referenced by ast_config_text_file_save().

1937 {
1938  int precomment_lines;
1939  int i;
1940 
1941  if (!fi) {
1942  /* No file scratch pad object so insert no blank lines. */
1943  return;
1944  }
1945 
1946  precomment_lines = count_linefeeds_in_comments(precomments);
1947 
1948  /* I don't have to worry about those ;! comments, they are
1949  stored in the precomments, but not printed back out.
1950  I did have to make sure that comments following
1951  the ;! header comments were not also deleted in the process */
1952  if (lineno - precomment_lines - fi->lineno < 0) { /* insertions can mess up the line numbering and produce negative numbers that mess things up */
1953  return;
1954  } else if (lineno == 0) {
1955  /* Line replacements also mess things up */
1956  return;
1957  } else if (lineno - precomment_lines - fi->lineno < 5) {
1958  /* Only insert less than 5 blank lines; if anything more occurs,
1959  * it's probably due to context deletion. */
1960  for (i = fi->lineno; i < lineno - precomment_lines; i++) {
1961  fprintf(fp, "\n");
1962  }
1963  } else {
1964  /* Deletion occurred - insert a single blank line, for separation of
1965  * contexts. */
1966  fprintf(fp, "\n");
1967  }
1968 
1969  fi->lineno = lineno + 1; /* Advance the file lineno */
1970 }
static int count_linefeeds_in_comments(struct ast_comment *x)
Definition: config.c:1925
int lineno
Definition: config.c:159
static void make_fn ( char *  fn,
size_t  fn_size,
const char *  file,
const char *  configfile 
)
static

Definition at line 1866 of file config.c.

References ast_config_AST_CONFIG_DIR, ast_copy_string(), and ast_strlen_zero().

Referenced by ast_config_text_file_save(), and set_fn().

1867 {
1868  if (ast_strlen_zero(file)) {
1869  if (configfile[0] == '/') {
1870  ast_copy_string(fn, configfile, fn_size);
1871  } else {
1872  snprintf(fn, fn_size, "%s/%s", ast_config_AST_CONFIG_DIR, configfile);
1873  }
1874  } else if (file[0] == '/') {
1875  ast_copy_string(fn, file, fn_size);
1876  } else {
1877  snprintf(fn, fn_size, "%s/%s", ast_config_AST_CONFIG_DIR, file);
1878  }
1879 }
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
const char * ast_config_AST_CONFIG_DIR
Definition: asterisk.c:256
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
static void move_variables ( struct ast_category old,
struct ast_category new 
)
static

Definition at line 664 of file config.c.

References ast_variable_append(), ast_category::root, and var.

Referenced by process_text_line().

665 {
666  struct ast_variable *var = old->root;
667 
668  old->root = NULL;
669  /* we can just move the entire list in a single op */
670  ast_variable_append(new, var);
671 }
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
#define var
Definition: ast_expr2f.c:606
struct ast_variable * root
Definition: config.c:229
void ast_variable_append(struct ast_category *category, struct ast_variable *variable)
Definition: config.c:483
static struct ast_category* next_available_category ( struct ast_category cat)
static

Definition at line 788 of file config.c.

References ast_category::ignored, and ast_category::next.

Referenced by ast_category_browse().

789 {
790  for (; cat && cat->ignored; cat = cat->next);
791 
792  return cat;
793 }
int ignored
Definition: config.c:216
struct ast_category * next
Definition: config.c:233
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 
)
static

parse one line in the configuration.

* We can have a category header  [foo](...)
* a directive           #include / #exec
* or a regular line        name = value
* 

Definition at line 1255 of file config.c.

References ALLOC_COMMENT(), appendbuf, ast_category_append(), ast_category_destroy(), ast_category_first(), ast_category_new(), ast_config_internal_load(), ast_include_new(), ast_log(), ast_opt_exec_includes, ast_safe_system(), ast_skip_blanks(), ast_str_append(), ast_str_buffer(), ast_str_set(), ast_str_trim_blanks(), ast_strip(), ast_strlen_zero(), ast_test_flag, ast_threadstorage_get(), ast_tvnow(), ast_variable_append(), ast_variable_new(), ast_variable_update(), ATTRIBUTE_EXEC, ATTRIBUTE_INCLUDE, ast_variable::blanklines, category_get(), CB_RESET(), config_cache_attribute(), CONFIG_FLAG_NOCACHE, CONFIG_FLAG_WITHCOMMENTS, ast_config::include_level, inherit_category(), ast_variable::lineno, ast_category::lineno, LOG_ERROR, LOG_WARNING, move_variables(), ast_variable::name, ast_variable::next, ast_variable::object, ast_variable::precomments, ast_category::precomments, replace(), S_OR, ast_variable::sameline, ast_category::sameline, str, strsep(), ast_variable::value, and var.

Referenced by config_text_file_load().

1261 {
1262  char *c;
1263  char *cur = buf;
1264  struct ast_variable *v;
1265  char cmd[512], exec_file[512];
1266 
1267  /* Actually parse the entry */
1268  if (cur[0] == '[') { /* A category header */
1269  /* format is one of the following:
1270  * [foo] define a new category named 'foo'
1271  * [foo](!) define a new template category named 'foo'
1272  * [foo](+) append to category 'foo', error if foo does not exist.
1273  * [foo](a) define a new category and inherit from template a.
1274  * You can put a comma-separated list of templates and '!' and '+'
1275  * between parentheses, with obvious meaning.
1276  */
1277  struct ast_category *newcat = NULL;
1278  char *catname;
1279 
1280  c = strchr(cur, ']');
1281  if (!c) {
1282  ast_log(LOG_WARNING, "parse error: no closing ']', line %d of %s\n", lineno, configfile);
1283  return -1;
1284  }
1285  *c++ = '\0';
1286  cur++;
1287  if (*c++ != '(')
1288  c = NULL;
1289  catname = cur;
1290  if (!(*cat = newcat = ast_category_new(catname,
1291  S_OR(suggested_include_file, cfg->include_level == 1 ? "" : configfile),
1292  lineno))) {
1293  return -1;
1294  }
1295  (*cat)->lineno = lineno;
1296  *last_var = 0;
1297  *last_cat = newcat;
1298 
1299  /* add comments */
1301  newcat->precomments = ALLOC_COMMENT(comment_buffer);
1303  newcat->sameline = ALLOC_COMMENT(lline_buffer);
1305  CB_RESET(comment_buffer, lline_buffer);
1306 
1307  /* If there are options or categories to inherit from, process them now */
1308  if (c) {
1309  if (!(cur = strchr(c, ')'))) {
1310  ast_log(LOG_WARNING, "parse error: no closing ')', line %d of %s\n", lineno, configfile);
1311  return -1;
1312  }
1313  *cur = '\0';
1314  while ((cur = strsep(&c, ","))) {
1315  if (!strcasecmp(cur, "!")) {
1316  (*cat)->ignored = 1;
1317  } else if (!strcasecmp(cur, "+")) {
1318  *cat = category_get(cfg, catname, 1);
1319  if (!(*cat)) {
1320  if (newcat)
1321  ast_category_destroy(newcat);
1322  ast_log(LOG_WARNING, "Category addition requested, but category '%s' does not exist, line %d of %s\n", catname, lineno, configfile);
1323  return -1;
1324  }
1325  if (newcat) {
1326  move_variables(newcat, *cat);
1327  ast_category_destroy(newcat);
1328  newcat = NULL;
1329  }
1330  } else {
1331  struct ast_category *base;
1332 
1333  base = category_get(cfg, cur, 1);
1334  if (!base) {
1335  ast_log(LOG_WARNING, "Inheritance requested, but category '%s' does not exist, line %d of %s\n", cur, lineno, configfile);
1336  return -1;
1337  }
1338  inherit_category(*cat, base);
1339  }
1340  }
1341  }
1342  if (newcat)
1343  ast_category_append(cfg, *cat);
1344  } else if (cur[0] == '#') { /* A directive - #include or #exec */
1345  char *cur2;
1346  char real_inclusion_name[256];
1347  int do_include = 0; /* otherwise, it is exec */
1348 
1349  cur++;
1350  c = cur;
1351  while (*c && (*c > 32)) {
1352  c++;
1353  }
1354 
1355  if (*c) {
1356  *c = '\0';
1357  /* Find real argument */
1358  c = ast_strip(c + 1);
1359  if (!(*c)) {
1360  c = NULL;
1361  }
1362  } else {
1363  c = NULL;
1364  }
1365  if (!strcasecmp(cur, "include")) {
1366  do_include = 1;
1367  } else if (!strcasecmp(cur, "exec")) {
1368  if (!ast_opt_exec_includes) {
1369  ast_log(LOG_WARNING, "Cannot perform #exec unless execincludes option is enabled in asterisk.conf (options section)!\n");
1370  return 0; /* XXX is this correct ? or we should return -1 ? */
1371  }
1372  } else {
1373  ast_log(LOG_WARNING, "Unknown directive '#%s' at line %d of %s\n", cur, lineno, configfile);
1374  return 0; /* XXX is this correct ? or we should return -1 ? */
1375  }
1376 
1377  if (c == NULL) {
1378  ast_log(LOG_WARNING, "Directive '#%s' needs an argument (%s) at line %d of %s\n",
1379  do_include ? "include" : "exec",
1380  do_include ? "filename" : "/path/to/executable",
1381  lineno,
1382  configfile);
1383  return 0; /* XXX is this correct ? or we should return -1 ? */
1384  }
1385 
1386  cur = c;
1387  /* Strip off leading and trailing "'s and <>'s */
1388  /* Dequote */
1389  if ((*c == '"') || (*c == '<')) {
1390  char quote_char = *c;
1391  if (quote_char == '<') {
1392  quote_char = '>';
1393  }
1394 
1395  if (*(c + strlen(c) - 1) == quote_char) {
1396  cur++;
1397  *(c + strlen(c) - 1) = '\0';
1398  }
1399  }
1400  cur2 = cur;
1401 
1402  /* #exec </path/to/executable>
1403  We create a tmp file, then we #include it, then we delete it. */
1404  if (!do_include) {
1405  struct timeval now = ast_tvnow();
1406  if (!ast_test_flag(&flags, CONFIG_FLAG_NOCACHE))
1407  config_cache_attribute(configfile, ATTRIBUTE_EXEC, NULL, who_asked);
1408  snprintf(exec_file, sizeof(exec_file), "/var/tmp/exec.%d%d.%ld", (int)now.tv_sec, (int)now.tv_usec, (long)pthread_self());
1409  snprintf(cmd, sizeof(cmd), "%s > %s 2>&1", cur, exec_file);
1410  ast_safe_system(cmd);
1411  cur = exec_file;
1412  } else {
1413  if (!ast_test_flag(&flags, CONFIG_FLAG_NOCACHE))
1414  config_cache_attribute(configfile, ATTRIBUTE_INCLUDE, cur, who_asked);
1415  exec_file[0] = '\0';
1416  }
1417  /* A #include */
1418  /* record this inclusion */
1419  ast_include_new(cfg, cfg->include_level == 1 ? "" : configfile, cur, !do_include, cur2, lineno, real_inclusion_name, sizeof(real_inclusion_name));
1420 
1421  do_include = ast_config_internal_load(cur, cfg, flags, real_inclusion_name, who_asked) ? 1 : 0;
1422  if (!ast_strlen_zero(exec_file))
1423  unlink(exec_file);
1424  if (!do_include) {
1425  ast_log(LOG_ERROR, "The file '%s' was listed as a #include but it does not exist.\n", cur);
1426  return -1;
1427  }
1428  /* XXX otherwise what ? the default return is 0 anyways */
1429 
1430  } else {
1431  /* Just a line (variable = value) */
1432  int object = 0;
1433  if (!(*cat)) {
1435  "parse error: No category context for line %d of %s\n", lineno, configfile);
1436  return -1;
1437  }
1438  c = strchr(cur, '=');
1439 
1440  if (c && c > cur && (*(c - 1) == '+')) {
1441  struct ast_variable *var, *replace = NULL;
1442  struct ast_str **str = ast_threadstorage_get(&appendbuf, sizeof(*str));
1443 
1444  if (!str || !*str) {
1445  return -1;
1446  }
1447 
1448  *(c - 1) = '\0';
1449  c++;
1450  cur = ast_strip(cur);
1451 
1452  /* Must iterate through category until we find last variable of same name (since there could be multiple) */
1453  for (var = ast_category_first(*cat); var; var = var->next) {
1454  if (!strcmp(var->name, cur)) {
1455  replace = var;
1456  }
1457  }
1458 
1459  if (!replace) {
1460  /* Nothing to replace; just set a variable normally. */
1461  goto set_new_variable;
1462  }
1463 
1464  ast_str_set(str, 0, "%s", replace->value);
1465  ast_str_append(str, 0, "%s", c);
1466  ast_str_trim_blanks(*str);
1467  ast_variable_update(*cat, replace->name, ast_skip_blanks(ast_str_buffer(*str)), replace->value, object);
1468  } else if (c) {
1469  *c = 0;
1470  c++;
1471  /* Ignore > in => */
1472  if (*c== '>') {
1473  object = 1;
1474  c++;
1475  }
1476 set_new_variable:
1477  if ((v = ast_variable_new(ast_strip(cur), ast_strip(c), S_OR(suggested_include_file, cfg->include_level == 1 ? "" : configfile)))) {
1478  v->lineno = lineno;
1479  v->object = object;
1480  *last_cat = 0;
1481  *last_var = v;
1482  /* Put and reset comments */
1483  v->blanklines = 0;
1484  ast_variable_append(*cat, v);
1485  /* add comments */
1487  v->precomments = ALLOC_COMMENT(comment_buffer);
1489  v->sameline = ALLOC_COMMENT(lline_buffer);
1491  CB_RESET(comment_buffer, lline_buffer);
1492 
1493  } else {
1494  return -1;
1495  }
1496  } else {
1497  ast_log(LOG_WARNING, "No '=' (equal sign) in line %d of %s\n", lineno, configfile);
1498  }
1499  }
1500  return 0;
1501 }
struct ast_comment * precomments
Definition: config.h:90
int ast_safe_system(const char *s)
Safely spawn an external program while closing file descriptors.
Definition: asterisk.c:1077
static void config_cache_attribute(const char *configfile, enum config_cache_attribute_enum attrtype, const char *filename, const char *who_asked)
Definition: config.c:1204
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
char * strsep(char **str, const char *delims)
struct ast_variable * ast_category_first(struct ast_category *cat)
given a pointer to a category, return the root variable.
Definition: config.c:796
#define ast_test_flag(p, flag)
Definition: utils.h:63
static struct ast_category * category_get(const struct ast_config *config, const char *category_name, int ignored)
Definition: config.c:691
#define LOG_WARNING
Definition: logger.h:144
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:497
int lineno
Definition: config.h:87
int include_level
Definition: config.c:243
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
int object
Definition: config.h:88
#define var
Definition: ast_expr2f.c:606
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:900
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:142
int lineno
Definition: config.c:223
const char * str
Definition: app_jack.c:144
struct ast_category * ast_category_new(const char *name, const char *in_file, int lineno)
Create a category structure.
Definition: config.c:673
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:874
#define ast_opt_exec_includes
Definition: options.h:104
void ast_category_destroy(struct ast_category *cat)
Definition: config.c:762
const char * value
Definition: config.h:79
static void inherit_category(struct ast_category *new, const struct ast_category *base)
Definition: config.c:872
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:155
static void CB_RESET(struct ast_str *cb, struct ast_str *llb)
Definition: config.c:132
const char * name
Definition: config.h:77
#define LOG_ERROR
Definition: logger.h:155
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: config.c:332
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:364
void ast_variable_append(struct ast_category *category, struct ast_variable *variable)
Definition: config.c:483
struct ast_comment * sameline
Definition: config.c:226
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
Definition: strings.h:97
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static struct ast_comment * ALLOC_COMMENT(struct ast_str *buffer)
Definition: config.c:142
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.
Definition: config.c:942
static int replace(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
Definition: func_strings.c:775
struct ast_comment * precomments
Definition: config.c:225
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:77
int blanklines
Definition: config.h:89
struct ast_comment * sameline
Definition: config.h:91
struct ast_variable * next
Definition: config.h:82
void ast_str_trim_blanks(struct ast_str *buf)
Trims trailing whitespace characters from an ast_str string.
Definition: strings.h:461
void ast_category_append(struct ast_config *config, struct ast_category *cat)
Definition: config.c:719
struct ast_config * ast_config_internal_load(const char *configfile, struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl_file, const char *who_asked)
Definition: config.c:2459
static void move_variables(struct ast_category *old, struct ast_category *new)
Definition: config.c:664
struct ast_variable * ast_variable_new(const char *name, const char *value, const char *filename)
Definition: config.c:278
static struct ast_threadstorage appendbuf
Definition: config.c:113
int read_config_maps ( void  )

Exposed re-initialization method for core process.

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

Definition at line 2298 of file config.c.

References append_mapping(), ast_config_destroy(), ast_config_internal_load(), ast_config_new(), ast_copy_string(), ast_log(), ast_variable_browse(), clear_config_maps(), config, CONFIG_FLAG_NOREALTIME, CONFIG_STATUS_FILEINVALID, LOG_ERROR, LOG_WARNING, ast_variable::name, ast_variable::next, strsep(), table, and ast_variable::value.

Referenced by main().

2299 {
2300  struct ast_config *config, *configtmp;
2301  struct ast_variable *v;
2302  char *driver, *table, *database, *textpri, *stringp, *tmp;
2303  struct ast_flags flags = { CONFIG_FLAG_NOREALTIME };
2304  int pri;
2305 
2307 
2308  configtmp = ast_config_new();
2309  if (!configtmp) {
2310  ast_log(LOG_ERROR, "Unable to allocate memory for new config\n");
2311  return -1;
2312  }
2313  config = ast_config_internal_load(extconfig_conf, configtmp, flags, "", "extconfig");
2314  if (config == CONFIG_STATUS_FILEINVALID) {
2315  return -1;
2316  } else if (!config) {
2317  ast_config_destroy(configtmp);
2318  return 0;
2319  }
2320 
2321  for (v = ast_variable_browse(config, "settings"); v; v = v->next) {
2322  char buf[512];
2323  ast_copy_string(buf, v->value, sizeof(buf));
2324  stringp = buf;
2325  driver = strsep(&stringp, ",");
2326 
2327  if ((tmp = strchr(stringp, '\"')))
2328  stringp = tmp;
2329 
2330  /* check if the database text starts with a double quote */
2331  if (*stringp == '"') {
2332  stringp++;
2333  database = strsep(&stringp, "\"");
2334  strsep(&stringp, ",");
2335  } else {
2336  /* apparently this text has no quotes */
2337  database = strsep(&stringp, ",");
2338  }
2339 
2340  table = strsep(&stringp, ",");
2341  textpri = strsep(&stringp, ",");
2342  if (!textpri || !(pri = atoi(textpri))) {
2343  pri = 1;
2344  }
2345 
2346  if (!strcmp(v->name, extconfig_conf)) {
2347  ast_log(LOG_WARNING, "Cannot bind '%s'!\n", extconfig_conf);
2348  continue;
2349  }
2350 
2351  if (!strcmp(v->name, "asterisk.conf")) {
2352  ast_log(LOG_WARNING, "Cannot bind 'asterisk.conf'!\n");
2353  continue;
2354  }
2355 
2356  if (!strcmp(v->name, "logger.conf")) {
2357  ast_log(LOG_WARNING, "Cannot bind 'logger.conf'!\n");
2358  continue;
2359  }
2360 
2361  if (!driver || !database)
2362  continue;
2363  if (!strcasecmp(v->name, "sipfriends")) {
2364  ast_log(LOG_WARNING, "The 'sipfriends' table is obsolete, update your config to use sippeers instead.\n");
2365  append_mapping("sippeers", driver, database, table ? table : "sipfriends", pri);
2366  } else if (!strcasecmp(v->name, "iaxfriends")) {
2367  ast_log(LOG_WARNING, "The 'iaxfriends' table is obsolete, update your config to use iaxusers and iaxpeers, though they can point to the same table.\n");
2368  append_mapping("iaxusers", driver, database, table ? table : "iaxfriends", pri);
2369  append_mapping("iaxpeers", driver, database, table ? table : "iaxfriends", pri);
2370  } else
2371  append_mapping(v->name, driver, database, table, pri);
2372  }
2373 
2374  ast_config_destroy(config);
2375  return 0;
2376 }
static const char config[]
Definition: cdr_csv.c:57
char * strsep(char **str, const char *delims)
#define LOG_WARNING
Definition: logger.h:144
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
Definition: config.c:597
unsigned int flags
Definition: utils.h:201
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
static char * extconfig_conf
Definition: config.c:69
static void clear_config_maps(void)
Definition: config.c:2248
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: config.c:1037
static char * table
Definition: cdr_odbc.c:50
static int append_mapping(const char *name, const char *driver, const char *database, const char *table, int priority)
Definition: config.c:2263
const char * value
Definition: config.h:79
const char * name
Definition: config.h:77
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
struct ast_config * ast_config_new(void)
Create a new base configuration structure.
Definition: config.c:888
Structure used to handle boolean flags.
Definition: utils.h:200
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
struct ast_variable * next
Definition: config.h:82
#define CONFIG_STATUS_FILEINVALID
Definition: config.h:52
struct ast_config * ast_config_internal_load(const char *configfile, struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl_file, const char *who_asked)
Definition: config.c:2459
int register_config_cli ( void  )

Exposed initialization method for core process.

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

Definition at line 3145 of file config.c.

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

Referenced by main().

3146 {
3149  return 0;
3150 }
static void config_shutdown(void)
Definition: config.c:3132
static struct ast_cli_entry cli_config[]
Definition: config.c:3126
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int ast_register_atexit(void(*func)(void))
Register a function to be executed before Asterisk exits.
Definition: asterisk.c:998
int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
Register multiple commands.
Definition: cli.c:2167
static struct inclfile* set_fn ( char *  fn,
size_t  fn_size,
const char *  file,
const char *  configfile,
struct ao2_container fileset 
)
static

Definition at line 1881 of file config.c.

References ao2_alloc, ao2_find, ao2_link, ao2_ref, ast_strdup, inclfile::fname, inclfile_destroy(), inclfile::lineno, make_fn(), and OBJ_POINTER.

Referenced by ast_config_text_file_save().

1882 {
1883  struct inclfile lookup;
1884  struct inclfile *fi;
1885 
1886  make_fn(fn, fn_size, file, configfile);
1887  lookup.fname = fn;
1888  fi = ao2_find(fileset, &lookup, OBJ_POINTER);
1889  if (fi) {
1890  /* Found existing include file scratch pad. */
1891  return fi;
1892  }
1893 
1894  /* set up a file scratch pad */
1895  fi = ao2_alloc(sizeof(struct inclfile), inclfile_destroy);
1896  if (!fi) {
1897  /* Scratch pad creation failed. */
1898  return NULL;
1899  }
1900  fi->fname = ast_strdup(fn);
1901  if (!fi->fname) {
1902  /* Scratch pad creation failed. */
1903  ao2_ref(fi, -1);
1904  return NULL;
1905  }
1906  fi->lineno = 1;
1907 
1908  ao2_link(fileset, fi);
1909 
1910  return fi;
1911 }
#define ao2_link(arg1, arg2)
Definition: astobj2.h:785
#define ast_strdup(a)
Definition: astmm.h:109
static void make_fn(char *fn, size_t fn_size, const char *file, const char *configfile)
Definition: config.c:1866
#define ao2_ref(o, delta)
Definition: astobj2.h:472
static void inclfile_destroy(void *obj)
Definition: config.c:1859
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:430
#define ao2_find(arg1, arg2, arg3)
Definition: astobj2.h:964
char * fname
Definition: config.c:158
int lineno
Definition: config.c:159
static struct ast_variable* variable_clone ( const struct ast_variable old)
static

Definition at line 650 of file config.c.

References ast_variable_new(), ast_variable::blanklines, ast_variable::file, ast_variable::lineno, ast_variable::name, ast_variable::object, and ast_variable::value.

Referenced by inherit_category().

651 {
652  struct ast_variable *new = ast_variable_new(old->name, old->value, old->file);
653 
654  if (new) {
655  new->lineno = old->lineno;
656  new->object = old->object;
657  new->blanklines = old->blanklines;
658  /* TODO: clone comments? */
659  }
660 
661  return new;
662 }
int lineno
Definition: config.h:87
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
int object
Definition: config.h:88
const char * value
Definition: config.h:79
const char * name
Definition: config.h:77
const char * file
Definition: config.h:85
int blanklines
Definition: config.h:89
struct ast_variable * ast_variable_new(const char *name, const char *value, const char *filename)
Definition: config.c:278

Variable Documentation

struct ast_threadstorage appendbuf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_appendbuf , .custom_init = init_appendbuf , }
static

Definition at line 113 of file config.c.

Referenced by process_text_line().

struct cfmtime_head cfmtime_head = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 } , }
static
struct ast_cli_entry cli_config[]
static
Initial value:
= {
AST_CLI_DEFINE(handle_cli_core_show_config_mappings, "Display config mappings (file names to config engines)"),
AST_CLI_DEFINE(handle_cli_config_reload, "Force a reload on modules using a particular configuration file"),
AST_CLI_DEFINE(handle_cli_config_list, "Show all files that have loaded a configuration file"),
}
#define AST_CLI_DEFINE(fn, txt,...)
Definition: cli.h:191
static char * handle_cli_config_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: config.c:3040
static char * handle_cli_core_show_config_mappings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: config.c:3003
static char * handle_cli_config_list(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: config.c:3102

Definition at line 3126 of file config.c.

struct ast_config_engine* config_engine_list
static

Definition at line 204 of file config.c.

ast_mutex_t config_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, 1 }
static
char* extconfig_conf = "extconfig.conf"
static

Definition at line 69 of file config.c.

struct ast_config_engine text_file_engine
static
Initial value:
= {
.name = "text",
.load_func = 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)
Definition: config.c:1503

Definition at line 2454 of file config.c.

Referenced by ast_config_internal_load().