Wed Jan 8 2020 09:50:10

Asterisk developer's documentation


config.h File Reference

Configuration File Parser. More...

Go to the source code of this file.

Data Structures

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

Macros

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

Typedefs

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

Enumerations

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

Functions

void ast_category_append (struct ast_config *config, struct ast_category *cat)
 
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...
 
void ast_config_destroy (struct ast_config *config)
 Destroys a config. More...
 
int ast_config_engine_deregister (struct ast_config_engine *del)
 Deregister config engine. More...
 
int ast_config_engine_register (struct ast_config_engine *newconfig)
 Register config engine. More...
 
struct ast_categoryast_config_get_current_category (const struct ast_config *cfg)
 Retrieve the current category name being built. More...
 
struct ast_configast_config_internal_load (const char *configfile, struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl_file, const char *who_asked)
 
struct ast_configast_config_load2 (const char *filename, const char *who_asked, struct ast_flags flags)
 Load a config file. More...
 
struct ast_configast_config_new (void)
 Create a new base configuration structure. More...
 
const char * ast_config_option (struct ast_config *cfg, const char *cat, const char *var)
 Retrieve a configuration variable within the configuration set. More...
 
void ast_config_set_current_category (struct ast_config *cfg, const struct ast_category *cat)
 Set the category within the configuration as being current. More...
 
int ast_config_text_file_save (const char *filename, const struct ast_config *cfg, const char *generator)
 
int ast_destroy_realtime (const char *family, const char *keyfield, const char *lookup,...) attribute_sentinel
 Destroy realtime configuration. More...
 
struct ast_config_includeast_include_find (struct ast_config *conf, const char *included_file)
 
struct ast_config_includeast_include_new (struct ast_config *conf, const char *from_file, const char *included_file, int is_exec, const char *exec_file, int from_lineno, char *real_included_file_name, int real_included_file_name_size)
 
void ast_include_rename (struct ast_config *conf, const char *from_file, const char *to_file)
 
struct ast_variableast_load_realtime (const char *family,...) attribute_sentinel
 Retrieve realtime configuration. More...
 
struct ast_variableast_load_realtime_all (const char *family,...) attribute_sentinel
 
struct ast_configast_load_realtime_multientry (const char *family,...) attribute_sentinel
 Retrieve realtime configuration. More...
 
int ast_parse_arg (const char *arg, enum ast_parse_flags flags, void *result,...)
 The argument parsing routine. More...
 
char * ast_realtime_decode_chunk (char *chunk)
 Remove standard encoding from realtime values, which ensures that a semicolon embedded within a single value is not treated upon retrieval as multiple values. More...
 
int ast_realtime_enabled (void)
 Check if there's any realtime engines loaded. 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,...) attribute_sentinel
 Inform realtime what fields that may be stored. More...
 
int ast_rq_is_int (require_type type)
 Check if require type is an integer type. More...
 
int ast_store_realtime (const char *family,...) attribute_sentinel
 Create realtime configuration. More...
 
int ast_unload_realtime (const char *family)
 Release any resources cached for a realtime family. More...
 
int ast_update2_realtime (const char *family,...) attribute_sentinel
 Update realtime configuration. More...
 
int ast_update_realtime (const char *family, const char *keyfield, const char *lookup,...) attribute_sentinel
 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)
 
void ast_variable_insert (struct ast_category *category, struct ast_variable *variable, const char *line)
 
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 *var)
 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...
 
int config_text_file_save (const char *filename, const struct ast_config *cfg, const char *generator)
 
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...
 

Detailed Description

Configuration File Parser.

Definition in file config.h.

Macro Definition Documentation

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

Load a config file.

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

Create a config structure from a given configuration file.

Returns
an ast_config data structure on success
Return values
NULLon error

Definition at line 170 of file config.h.

Referenced by adsi_load(), advanced_options(), aji_load_config(), ast_plc_reload(), conf_exec(), config_function_read(), config_load(), config_module(), directory_exec(), festival_exec(), find_conf(), gtalk_load_config(), handle_cli_dialplan_save(), jingle_load_config(), load_config(), load_config_meetme(), load_module(), load_moh_classes(), load_odbc_config(), load_pktccops_config(), make_email_file(), odbc_load_module(), osp_load(), parse_config(), pbx_load_config(), pbx_load_users(), play_message(), prep_email_sub_vars(), read_agent_config(), read_password_from_file(), realtime_directory(), reload(), reload_config(), reload_followme(), reload_module(), reload_queue_rules(), reload_queues(), set_config(), setup_dahdi_int(), sla_load_config(), smdi_load(), tds_load_module(), vm_change_password(), and vm_forwardoptions().

#define CV_BOOL (   __x,
  __dst 
)    CV_F(__x, (__dst) = ast_true(__val) )

helper macros to assign the value to a BOOL, UINT, static string and dynamic string

Definition at line 742 of file config.h.

Referenced by store_config_core().

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

Definition at line 745 of file config.h.

#define CV_END   } while (0)

close a variable parsing block

Definition at line 733 of file config.h.

Referenced by store_config_core(), and store_config_tone_zone().

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

call a generic function if the name matches.

Definition at line 736 of file config.h.

Referenced by store_config_core(), and store_config_tone_zone().

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

the macro to open a block for variable parsing

Definition at line 727 of file config.h.

Referenced by store_config_core(), and store_config_tone_zone().

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

Definition at line 744 of file config.h.

Referenced by store_config_core(), and store_config_tone_zone().

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

Definition at line 746 of file config.h.

Referenced by store_config_core().

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

Definition at line 743 of file config.h.

Referenced by store_config_core().

Typedef Documentation

typedef struct ast_config* config_load_func(const char *database, const char *table, const char *configfile, struct ast_config *config, struct ast_flags flags, const char *suggested_include_file, const char *who_asked)

Definition at line 100 of file config.h.

typedef int realtime_destroy(const char *database, const char *table, const char *keyfield, const char *entity, va_list ap)

Definition at line 106 of file config.h.

typedef struct ast_config* realtime_multi_get(const char *database, const char *table, va_list ap)

Definition at line 102 of file config.h.

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

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

Since
1.6.1

Definition at line 112 of file config.h.

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

Definition at line 105 of file config.h.

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

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

Since
1.6.1

Definition at line 118 of file config.h.

typedef int realtime_update(const char *database, const char *table, const char *keyfield, const char *entity, va_list ap)

Definition at line 103 of file config.h.

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

Definition at line 104 of file config.h.

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

Definition at line 101 of file config.h.

Enumeration Type Documentation

anonymous enum

Options for ast_config_load()

Enumerator
CONFIG_FLAG_WITHCOMMENTS 

Load the configuration, including comments

CONFIG_FLAG_FILEUNCHANGED 

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

CONFIG_FLAG_NOCACHE 

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

CONFIG_FLAG_NOREALTIME 

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

Definition at line 39 of file config.h.

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

Support code to parse config file arguments.

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

Returns
It returns 0 on success, != 0 otherwise.
Enumerator
PARSE_TYPE 
PARSE_INT32 
PARSE_UINT32 
PARSE_DOUBLE 
PARSE_ADDR 
PARSE_INADDR 
PARSE_DEFAULT 
PARSE_IN_RANGE 
PARSE_OUT_RANGE 
PARSE_PORT_MASK 
PARSE_PORT_IGNORE 
PARSE_PORT_REQUIRE 
PARSE_PORT_FORBID 

Definition at line 620 of file config.h.

620  {
621  /* low 4 bits of flags are used for the operand type */
622  PARSE_TYPE = 0x000f,
623  /* numeric types, with optional default value and bound checks.
624  * Additional arguments are passed by value.
625  */
626  PARSE_INT32 = 0x0001,
627  PARSE_UINT32 = 0x0002,
628  PARSE_DOUBLE = 0x0003,
629 #if 0 /* not supported yet */
630  PARSE_INT16 = 0x0004,
631  PARSE_UINT16 = 0x0005,
632 #endif
633 
634  /* Returns a struct ast_sockaddr, with optional default value
635  * (passed by reference) and port handling (accept, ignore,
636  * require, forbid). The format is 'ipaddress[:port]'. IPv6 address
637  * literals need square brackets around them if a port is specified.
638  */
639  PARSE_ADDR = 0x000e,
640 
641  /* Returns a struct sockaddr_in, with optional default value
642  * (passed by reference) and port handling (accept, ignore,
643  * require, forbid). The format is 'host.name[:port]'
644  */
645  PARSE_INADDR = 0x000f,
646 
647  /* Other data types can be added as needed */
648 
649  /* If PARSE_DEFAULT is set, next argument is a default value
650  * which is returned in case of error. The argument is passed
651  * by value in case of numeric types, by reference in other cases.
652  */
653  PARSE_DEFAULT = 0x0010, /* assign default on error */
654 
655  /* Request a range check, applicable to numbers. Two additional
656  * arguments are passed by value, specifying the low-high end of
657  * the range (inclusive). An error is returned if the value
658  * is outside or inside the range, respectively.
659  */
660  PARSE_IN_RANGE = 0x0020, /* accept values inside a range */
661  PARSE_OUT_RANGE = 0x0040, /* accept values outside a range */
662 
663  /* Port handling, for ast_sockaddr. accept/ignore/require/forbid
664  * port number after the hostname or address.
665  */
666  PARSE_PORT_MASK = 0x0300, /* 0x000: accept port if present */
667  PARSE_PORT_IGNORE = 0x0100, /* 0x100: ignore port if present */
668  PARSE_PORT_REQUIRE = 0x0200, /* 0x200: require port number */
669  PARSE_PORT_FORBID = 0x0300, /* 0x100: forbid port number */
670 };

Types used in ast_realtime_require_field.

Enumerator
RQ_INTEGER1 
RQ_UINTEGER1 
RQ_INTEGER2 
RQ_UINTEGER2 
RQ_INTEGER3 
RQ_UINTEGER3 
RQ_INTEGER4 
RQ_UINTEGER4 
RQ_INTEGER8 
RQ_UINTEGER8 
RQ_CHAR 
RQ_FLOAT 
RQ_DATE 
RQ_DATETIME 

Definition at line 57 of file config.h.

57  {
68  RQ_CHAR,
69  RQ_FLOAT,
70  RQ_DATE,
72 } require_type;
Definition: config.h:68
require_type
Types used in ast_realtime_require_field.
Definition: config.h:57
Definition: config.h:70

Function Documentation

void ast_category_append ( struct ast_config config,
struct ast_category cat 
)

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.

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

return the first var of a category

Definition at line 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
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 
1044  ast_includes_destroy(cfg->includes);
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
struct ast_variable * root
Definition: config.c:229
#define ast_free(a)
Definition: astmm.h:97
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 *  configfile,
struct ast_config cfg,
struct ast_flags  flags,
const char *  suggested_incl_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 *  filename,
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
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
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
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,
  ... 
)

The argument parsing routine.

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

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

The argument parsing routine.

Definition at line 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_rq_is_int ( require_type  type)
inline

Check if require type is an integer type.

Definition at line 768 of file config.h.

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

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
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
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
int config_text_file_save ( const char *  filename,
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
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