Wed Oct 28 11:46:07 2009

Asterisk developer's documentation


config.h File Reference

Configuration File Parser. More...

#include "asterisk/utils.h"

Include dependency graph for config.h:

Go to the source code of this file.

Data Structures

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

Defines

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

Typedefs

typedef 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_store (const char *database, const char *table, va_list ap)
typedef int realtime_update (const char *database, const char *table, const char *keyfield, const char *entity, 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) }
enum  ast_parse_flags {
  PARSE_TYPE = 0x000f, PARSE_INT32 = 0x0001, PARSE_UINT32 = 0x0002, PARSE_DOUBLE = 0x0003,
  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...

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.
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.
int ast_category_exist (const struct ast_config *config, const char *category_name)
 Check for category duplicates.
struct ast_variableast_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())
struct ast_categoryast_category_get (const struct ast_config *config, const char *category_name)
 Retrieve a category if it exists.
void ast_category_insert (struct ast_config *config, struct ast_category *cat, const char *match)
 Inserts new category.
struct ast_categoryast_category_new (const char *name, const char *in_file, int lineno)
 Create a category structure.
void ast_category_rename (struct ast_category *cat, const char *name)
struct ast_variableast_category_root (struct ast_config *config, char *cat)
 returns the root ast_variable of a config
int ast_check_realtime (const char *family)
 Check if realtime engine is configured for family.
void ast_config_destroy (struct ast_config *config)
 Destroys a config.
int ast_config_engine_deregister (struct ast_config_engine *del)
 Deregister config engine.
int ast_config_engine_register (struct ast_config_engine *newconfig)
 Register config engine.
struct ast_categoryast_config_get_current_category (const struct ast_config *cfg)
 Retrieve the current category name being built. API for backend configuration engines while building a configuration set.
struct ast_configast_config_internal_load (const char *configfile, struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl_file, const char *who_asked)
struct ast_configast_config_load2 (const char *filename, const char *who_asked, struct ast_flags flags)
 Load a config file.
struct ast_configast_config_new (void)
 Create a new base configuration structure.
const char * ast_config_option (struct ast_config *cfg, const char *cat, const char *var)
 Retrieve a configuration variable within the configuration set. 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.
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.
int ast_destroy_realtime (const char *family, const char *keyfield, const char *lookup,...)
 Destroy realtime configuration.
struct ast_config_includeast_include_find (struct ast_config *conf, const char *included_file)
struct ast_config_includeast_include_new (struct ast_config *conf, const char *from_file, const char *included_file, int 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,...)
 Retrieve realtime configuration.
struct ast_variableast_load_realtime_all (const char *family,...)
struct ast_configast_load_realtime_multientry (const char *family,...)
 Retrieve realtime configuration.
int ast_parse_arg (const char *arg, enum ast_parse_flags flags, void *result,...)
 The argument parsing routine.
int ast_realtime_enabled (void)
 Check if there's any realtime engines loaded.
int ast_store_realtime (const char *family,...)
 Create realtime configuration.
int ast_update_realtime (const char *family, const char *keyfield, const char *lookup,...)
 Update realtime configuration.
void ast_variable_append (struct ast_category *category, struct ast_variable *variable)
struct ast_variableast_variable_browse (const struct ast_config *config, const char *category)
 Goes through variables Somewhat similar in intent as the ast_category_browse. List variables of config file category.
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.
int ast_variable_update (struct ast_category *category, const char *variable, const char *value, const char *match, unsigned int object)
void ast_variables_destroy (struct ast_variable *var)
 Free variable list.
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 This method is intended for use only with the core re-initialization and is not designed to be called from any user applications.
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.


Detailed Description

Configuration File Parser.

Definition in file config.h.


Define Documentation

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

#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

Definition at line 455 of file config.h.

Referenced by store_config(), and store_config_core().

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

Definition at line 458 of file config.h.

#define CV_END   } while (0)

close a variable parsing block

Definition at line 447 of file config.h.

Referenced by store_config(), and store_config_core().

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

call a generic function if the name matches.

Definition at line 450 of file config.h.

Referenced by store_config(), and store_config_core().

#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 441 of file config.h.

Referenced by store_config(), and store_config_core().

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

Definition at line 457 of file config.h.

Referenced by store_config_core().

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

Definition at line 459 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 456 of file config.h.

Referenced by store_config(), and 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 67 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 72 of file config.h.

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

Definition at line 69 of file config.h.

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

Definition at line 71 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 70 of file config.h.

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

Definition at line 68 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.

Definition at line 38 of file config.h.

00038      {
00039    /*! Load the configuration, including comments */
00040    CONFIG_FLAG_WITHCOMMENTS  = (1 << 0),
00041    /*! On a reload, give us a -1 if the file hasn't changed. */
00042    CONFIG_FLAG_FILEUNCHANGED = (1 << 1),
00043    /*! Don't attempt to cache mtime on this config file. */
00044    CONFIG_FLAG_NOCACHE       = (1 << 2),
00045 };

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. It returns 0 on success, != 0 otherwise.

Enumerator:
PARSE_TYPE 
PARSE_INT32 
PARSE_UINT32 
PARSE_DOUBLE 
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 346 of file config.h.

00346                      {
00347    /* low 4 bits of flags are used for the operand type */
00348    PARSE_TYPE  =  0x000f,
00349    /* numeric types, with optional default value and bound checks.
00350     * Additional arguments are passed by value.
00351     */
00352    PARSE_INT32 =  0x0001,
00353    PARSE_UINT32   =  0x0002,
00354    PARSE_DOUBLE   =  0x0003,
00355 #if 0 /* not supported yet */
00356    PARSE_INT16 =  0x0004,
00357    PARSE_UINT16   =  0x0005,
00358 #endif
00359    /* Returns a struct sockaddr_in, with optional default value
00360     * (passed by reference) and port handling (accept, ignore,
00361     * require, forbid). The format is 'host.name[:port]'
00362     */
00363    PARSE_INADDR   =  0x000f,
00364 
00365    /* Other data types can be added as needed */
00366 
00367    /* If PARSE_DEFAULT is set, next argument is a default value
00368     * which is returned in case of error. The argument is passed
00369     * by value in case of numeric types, by reference in other cases.
00370     */
00371    PARSE_DEFAULT  =  0x0010,  /* assign default on error */
00372 
00373    /* Request a range check, applicable to numbers. Two additional
00374     * arguments are passed by value, specifying the low-high end of
00375     * the range (inclusive). An error is returned if the value
00376     * is outside or inside the range, respectively.
00377     */
00378    PARSE_IN_RANGE =  0x0020,  /* accept values inside a range */
00379    PARSE_OUT_RANGE = 0x0040,  /* accept values outside a range */
00380 
00381    /* Port handling, for sockaddr_in. accept/ignore/require/forbid
00382     * port number after the hostname or address.
00383     */
00384    PARSE_PORT_MASK = 0x0300, /* 0x000: accept port if present */
00385    PARSE_PORT_IGNORE =  0x0100, /* 0x100: ignore port if present */
00386    PARSE_PORT_REQUIRE = 0x0200, /* 0x200: require port number */
00387    PARSE_PORT_FORBID =  0x0300, /* 0x100: forbid port number */
00388 };


Function Documentation

void ast_category_append ( struct ast_config config,
struct ast_category cat 
)

Definition at line 478 of file config.c.

References ast_config::current, ast_config::include_level, ast_category::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(), and realtime_multi_pgsql().

00479 {
00480    if (config->last)
00481       config->last->next = category;
00482    else
00483       config->root = category;
00484    category->include_level = config->include_level;
00485    config->last = category;
00486    config->current = category;
00487 }

char* ast_category_browse ( struct ast_config config,
const char *  prev 
)

Goes through categories.

Parameters:
config Which config structure you wish to "browse"
prev A 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:
a category on success
NULL on failure/no-more-categories

Definition at line 588 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(), aji_load_config(), complete_sipnotify(), find_queue_by_name_rt(), get_insecure_variable_from_config(), gtalk_load_config(), iax_provision_reload(), ind_load_module(), jingle_load_config(), load_config(), load_module(), load_moh_classes(), load_odbc_config(), misdn_cfg_init(), osp_load(), parse_config(), pbx_load_config(), pbx_load_users(), read_agent_config(), realtime_directory(), realtime_switch_common(), reload(), reload_config(), reload_followme(), reload_queue_rules(), reload_queues(), rpt_master(), search_directory(), set_config(), setup_dahdi(), show_users_realtime(), sla_load_config(), update_realtime_members(), and vm_change_password().

00589 {  
00590    struct ast_category *cat = NULL;
00591 
00592    if (prev && config->last_browse && (config->last_browse->name == prev))
00593       cat = config->last_browse->next;
00594    else if (!prev && config->root)
00595       cat = config->root;
00596    else if (prev) {
00597       for (cat = config->root; cat; cat = cat->next) {
00598          if (cat->name == prev) {
00599             cat = cat->next;
00600             break;
00601          }
00602       }
00603       if (!cat) {
00604          for (cat = config->root; cat; cat = cat->next) {
00605             if (!strcasecmp(cat->name, prev)) {
00606                cat = cat->next;
00607                break;
00608             }
00609          }
00610       }
00611    }
00612    
00613    if (cat)
00614       cat = next_available_category(cat);
00615 
00616    config->last_browse = cat;
00617    return (cat) ? cat->name : NULL;
00618 }

int ast_category_delete ( struct ast_config cfg,
const char *  category 
)

Definition at line 753 of file config.c.

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

Referenced by handle_updates().

00754 {
00755    struct ast_category *prev=NULL, *cat;
00756 
00757    cat = cfg->root;
00758    while (cat) {
00759       if (cat->name == category) {
00760          if (prev) {
00761             prev->next = cat->next;
00762             if (cat == cfg->last)
00763                cfg->last = prev;
00764          } else {
00765             cfg->root = cat->next;
00766             if (cat == cfg->last)
00767                cfg->last = NULL;
00768          }
00769          ast_category_destroy(cat);
00770          return 0;
00771       }
00772       prev = cat;
00773       cat = cat->next;
00774    }
00775 
00776    prev = NULL;
00777    cat = cfg->root;
00778    while (cat) {
00779       if (!strcasecmp(cat->name, category)) {
00780          if (prev) {
00781             prev->next = cat->next;
00782             if (cat == cfg->last)
00783                cfg->last = prev;
00784          } else {
00785             cfg->root = cat->next;
00786             if (cat == cfg->last)
00787                cfg->last = NULL;
00788          }
00789          ast_category_destroy(cat);
00790          return 0;
00791       }
00792       prev = cat;
00793       cat = cat->next;
00794    }
00795    return -1;
00796 }

void ast_category_destroy ( struct ast_category cat  ) 

Definition at line 538 of file config.c.

References ast_destroy_comments(), ast_destroy_template_list(), ast_free, ast_variables_destroy(), ast_category::file, free, and ast_category::root.

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

00539 {
00540    ast_variables_destroy(cat->root);
00541    if (cat->file) {
00542       free(cat->file);
00543       cat->file = 0;
00544    }
00545    ast_destroy_comments(cat);
00546    ast_destroy_template_list(cat);
00547    ast_free(cat);
00548 }

struct ast_variable* ast_category_detach_variables ( struct ast_category cat  )  [read]

Definition at line 620 of file config.c.

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

Referenced by realtime_switch_common().

00621 {
00622    struct ast_variable *v;
00623 
00624    v = cat->root;
00625    cat->root = NULL;
00626    cat->last = NULL;
00627 
00628    return v;
00629 }

int ast_category_empty ( struct ast_config cfg,
const char *  category 
)

Removes and destroys all variables within a category.

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

Definition at line 798 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().

00799 {
00800    struct ast_category *cat;
00801 
00802    for (cat = cfg->root; cat; cat = cat->next) {
00803       if (!strcasecmp(cat->name, category))
00804          continue;
00805       ast_variables_destroy(cat->root);
00806       cat->root = NULL;
00807       cat->last = NULL;
00808       return 0;
00809    }
00810 
00811    return -1;
00812 }

int ast_category_exist ( const struct ast_config config,
const char *  category_name 
)

Check for category duplicates.

Parameters:
config which config to use
category_name name 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 473 of file config.c.

References ast_category_get().

00474 {
00475    return !!ast_category_get(config, category_name);
00476 }

struct ast_variable* ast_category_first ( struct ast_category cat  )  [read]

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

References ast_category::root.

00575 {
00576    return (cat) ? cat->root : NULL;
00577 }

struct ast_category* ast_category_get ( const struct ast_config config,
const char *  category_name 
) [read]

Retrieve a category if it exists.

Parameters:
config which config to use
category_name name of the category you're looking for This will search through the categories within a given config file for a match.
Return values:
pointer to category if found
NULL if not.

Definition at line 468 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().

00469 {
00470    return category_get(config, category_name, 0);
00471 }

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

Inserts new category.

Parameters:
config which config to use
cat newly created category to insert
match which category to insert above This function is used to insert a new category above another category matching the match parameter.

Definition at line 489 of file config.c.

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

Referenced by handle_updates().

00490 {
00491    struct ast_category *cur_category;
00492 
00493    if (!cat || !match)
00494       return;
00495    if (!strcasecmp(config->root->name, match)) {
00496       cat->next = config->root;
00497       config->root = cat;
00498       return;
00499    } 
00500    for (cur_category = config->root; cur_category; cur_category = cur_category->next) {
00501       if (!strcasecmp(cur_category->next->name, match)) {
00502          cat->next = cur_category->next;
00503          cur_category->next = cat;
00504          break;
00505       }
00506    }
00507 }

struct ast_category* ast_category_new ( const char *  name,
const char *  in_file,
int  lineno 
) [read]

Create a category structure.

Definition at line 439 of file config.c.

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

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

00440 {
00441    struct ast_category *category;
00442 
00443    if ((category = ast_calloc(1, sizeof(*category))))
00444       ast_copy_string(category->name, name, sizeof(category->name));
00445    category->file = strdup(in_file);
00446    category->lineno = lineno; /* if you don't know the lineno, set it to 999999 or something real big */
00447    return category;
00448 }

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

Definition at line 631 of file config.c.

References ast_copy_string(), and ast_category::name.

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

00632 {
00633    ast_copy_string(cat->name, name, sizeof(cat->name));
00634 }

struct ast_variable* ast_category_root ( struct ast_config config,
char *  cat 
) [read]

returns the root ast_variable of a config

Parameters:
config pointer to an ast_config data structure
cat name of the category for which you want the root
Returns the category specified

Definition at line 579 of file config.c.

References ast_category_get(), and ast_category::root.

Referenced by get_insecure_variable_from_config().

00580 {
00581    struct ast_category *category = ast_category_get(config, cat);
00582 
00583    if (category)
00584       return category->root;
00585    return NULL;
00586 }

int ast_check_realtime ( const char *  family  ) 

Check if realtime engine is configured for family.

Parameters:
family which family/config to be checked
Returns:
1 if family is configured in realtime and engine exists

Definition at line 2102 of file config.c.

References find_engine().

Referenced by __queues_show(), _sip_show_peer(), _sip_show_peers(), ast_queue_log(), close_mailbox(), copy_plain_file(), destroy_association(), handle_response_peerpoke(), handle_voicemail_show_users(), leave_voicemail(), local_ast_moh_start(), realtime_peer(), realtime_update_peer(), rename_file(), sip_poke_noanswer(), sip_show_settings(), and vm_delete().

02103 {
02104    struct ast_config_engine *eng;
02105 
02106    eng = find_engine(family, NULL, 0, NULL, 0);
02107    if (eng)
02108       return 1;
02109    return 0;
02110 }

void ast_config_destroy ( struct ast_config config  ) 

Destroys a config.

Parameters:
config pointer to config data structure Free memory associated with a given config

Definition at line 814 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_rtp_reload(), __ast_udptl_reload(), __init_manager(), __queues_show(), action_getconfig(), action_getconfigjson(), action_listcategories(), action_updateconfig(), adsi_load(), advanced_options(), aji_load_config(), ast_config_load2(), ast_readconfig(), conf_exec(), config_module(), directory_exec(), do_reload(), festival_exec(), find_conf(), handle_cli_dialplan_save(), iax_provision_reload(), ind_load_module(), init_logger_chain(), load_config(), load_config_meetme(), load_module(), load_modules(), load_moh_classes(), load_odbc_config(), load_realtime_queue(), load_rpt_vars(), 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(), read_agent_config(), read_config_maps(), realtime_directory(), realtime_multi_handler(), realtime_peer(), realtime_switch_common(), reload(), reload_config(), reload_followme(), reload_queue_rules(), reload_queues(), rpt_master(), run_startup_commands(), set_config(), setup_dahdi(), show_users_realtime(), sla_load_config(), smdi_load(), store_config(), tds_load_module(), unload_module(), update_realtime_members(), and vm_forwardoptions().

00815 {
00816    struct ast_category *cat, *catn;
00817 
00818    if (!cfg)
00819       return;
00820 
00821    ast_includes_destroy(cfg->includes);
00822 
00823    cat = cfg->root;
00824    while (cat) {
00825       catn = cat;
00826       cat = cat->next;
00827       ast_category_destroy(catn);
00828    }
00829    ast_free(cfg);
00830 }

int ast_config_engine_deregister ( struct ast_config_engine del  ) 

Deregister config engine.

Return values:
0 Always

Definition at line 1928 of file config.c.

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

Referenced by unload_module().

01929 {
01930    struct ast_config_engine *ptr, *last=NULL;
01931 
01932    ast_mutex_lock(&config_lock);
01933 
01934    for (ptr = config_engine_list; ptr; ptr=ptr->next) {
01935       if (ptr == del) {
01936          if (last)
01937             last->next = ptr->next;
01938          else
01939             config_engine_list = ptr->next;
01940          break;
01941       }
01942       last = ptr;
01943    }
01944 
01945    ast_mutex_unlock(&config_lock);
01946 
01947    return 0;
01948 }

int ast_config_engine_register ( struct ast_config_engine newconfig  ) 

Register config engine.

Return values:
1 Always

Definition at line 1909 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().

01910 {
01911    struct ast_config_engine *ptr;
01912 
01913    ast_mutex_lock(&config_lock);
01914 
01915    if (!config_engine_list) {
01916       config_engine_list = new;
01917    } else {
01918       for (ptr = config_engine_list; ptr->next; ptr=ptr->next);
01919       ptr->next = new;
01920    }
01921 
01922    ast_mutex_unlock(&config_lock);
01923    ast_log(LOG_NOTICE,"Registered Config Engine %s\n", new->name);
01924 
01925    return 1;
01926 }

struct ast_category* ast_config_get_current_category ( const struct ast_config cfg  )  [read]

Retrieve the current category name being built. API for backend configuration engines while building a configuration set.

Definition at line 832 of file config.c.

References ast_config::current.

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

00833 {
00834    return cfg->current;
00835 }

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 
) [read]

Definition at line 1990 of file config.c.

References ast_log(), CONFIG_STATUS_FILEUNCHANGED, db, find_engine(), ast_config::include_level, ast_config_engine::load_func, LOG_WARNING, ast_config::max_include_level, and table.

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

01991 {
01992    char db[256];
01993    char table[256];
01994    struct ast_config_engine *loader = &text_file_engine;
01995    struct ast_config *result; 
01996 
01997    /* The config file itself bumps include_level by 1 */
01998    if (cfg->max_include_level > 0 && cfg->include_level == cfg->max_include_level + 1) {
01999       ast_log(LOG_WARNING, "Maximum Include level (%d) exceeded\n", cfg->max_include_level);
02000       return NULL;
02001    }
02002 
02003    cfg->include_level++;
02004 
02005    if (strcmp(filename, extconfig_conf) && strcmp(filename, "asterisk.conf") && config_engine_list) {
02006       struct ast_config_engine *eng;
02007 
02008       eng = find_engine(filename, db, sizeof(db), table, sizeof(table));
02009 
02010 
02011       if (eng && eng->load_func) {
02012          loader = eng;
02013       } else {
02014          eng = find_engine("global", db, sizeof(db), table, sizeof(table));
02015          if (eng && eng->load_func)
02016             loader = eng;
02017       }
02018    }
02019 
02020    result = loader->load_func(db, table, filename, cfg, flags, suggested_include_file, who_asked);
02021 
02022    if (result && result != CONFIG_STATUS_FILEUNCHANGED)
02023       result->include_level--;
02024    else
02025       cfg->include_level--;
02026 
02027    return result;
02028 }

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

Load a config file.

Parameters:
filename path of file to open. If no preceding '/' character, path is considered relative to AST_CONFIG_DIR Create a config structure from a given configuration file.
who_asked The module which is making this request.
flags Optional 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).
Returns:
an ast_config data structure on success
Return values:
NULL on error

Definition at line 2030 of file config.c.

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

02031 {
02032    struct ast_config *cfg;
02033    struct ast_config *result;
02034 
02035    cfg = ast_config_new();
02036    if (!cfg)
02037       return NULL;
02038 
02039    result = ast_config_internal_load(filename, cfg, flags, "", who_asked);
02040    if (!result || result == CONFIG_STATUS_FILEUNCHANGED)
02041       ast_config_destroy(cfg);
02042 
02043    return result;
02044 }

struct ast_config* ast_config_new ( void   )  [read]

Create a new base configuration structure.

Definition at line 648 of file config.c.

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

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

00649 {
00650    struct ast_config *config;
00651 
00652    if ((config = ast_calloc(1, sizeof(*config))))
00653       config->max_include_level = MAX_INCLUDE_LEVEL;
00654    return config;
00655 }

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

References ast_variable_retrieve().

Referenced by load_config(), pbx_load_users(), and search_directory().

00386 {
00387    const char *tmp;
00388    tmp = ast_variable_retrieve(cfg, cat, var);
00389    if (!tmp)
00390       tmp = ast_variable_retrieve(cfg, "general", var);
00391    return tmp;
00392 }

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

References ast_config::current.

00838 {
00839    /* cast below is just to silence compiler warning about dropping "const" */
00840    cfg->current = (struct ast_category *) cat;
00841 }

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

Destroy realtime configuration.

Parameters:
family which family/config to be destroyed
keyfield which field to use as the key
lookup which 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.

Definition at line 2168 of file config.c.

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

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

02168                                                                                             {
02169    struct ast_config_engine *eng;
02170    int res = -1;
02171    char db[256]="";
02172    char table[256]="";
02173    va_list ap;
02174 
02175    va_start(ap, lookup);
02176    eng = find_engine(family, db, sizeof(db), table, sizeof(table));
02177    if (eng && eng->destroy_func) 
02178       res = eng->destroy_func(db, table, keyfield, lookup, ap);
02179    va_end(ap);
02180 
02181    return res;
02182 }

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

Definition at line 316 of file config.c.

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

Referenced by ast_include_new().

00317 {
00318    struct ast_config_include *x;
00319    for (x=conf->includes;x;x=x->next) {
00320       if (strcmp(x->included_file,included_file) == 0)
00321          return x;
00322    }
00323    return 0;
00324 }

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 
) [read]

Definition at line 225 of file config.c.

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

Referenced by process_text_line().

00226 {
00227    /* a file should be included ONCE. Otherwise, if one of the instances is changed,
00228     * then all be changed. -- how do we know to include it? -- Handling modified 
00229     * instances is possible, I'd have
00230     * to create a new master for each instance. */
00231    struct ast_config_include *inc;
00232    struct stat statbuf;
00233    
00234    inc = ast_include_find(conf, included_file);
00235    if (inc) {
00236       do {
00237          inc->inclusion_count++;
00238          snprintf(real_included_file_name, real_included_file_name_size, "%s~~%d", included_file, inc->inclusion_count);
00239       } while (stat(real_included_file_name, &statbuf) == 0);
00240       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);
00241    } else
00242       *real_included_file_name = 0;
00243    
00244    inc = ast_calloc(1,sizeof(struct ast_config_include));
00245    inc->include_location_file = ast_strdup(from_file);
00246    inc->include_location_lineno = from_lineno;
00247    if (!ast_strlen_zero(real_included_file_name))
00248       inc->included_file = ast_strdup(real_included_file_name);
00249    else
00250       inc->included_file = ast_strdup(included_file);
00251    
00252    inc->exec = is_exec;
00253    if (is_exec)
00254       inc->exec_file = ast_strdup(exec_file);
00255    
00256    /* attach this new struct to the conf struct */
00257    inc->next = conf->includes;
00258    conf->includes = inc;
00259    
00260    return inc;
00261 }

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

Definition at line 263 of file config.c.

References ast_variable::file, ast_category::file, free, ast_config_include::include_location_file, ast_config::includes, ast_variable::next, ast_category::next, ast_config_include::next, ast_category::root, ast_config::root, and strdup.

Referenced by action_updateconfig().

00264 {
00265    struct ast_config_include *incl;
00266    struct ast_category *cat;
00267    struct ast_variable *v;
00268    
00269    int from_len = strlen(from_file);
00270    int to_len = strlen(to_file);
00271    
00272    if (strcmp(from_file, to_file) == 0) /* no use wasting time if the name is the same */
00273       return;
00274    
00275    /* the manager code allows you to read in one config file, then
00276     * write it back out under a different name. But, the new arrangement
00277     * ties output lines to the file name. So, before you try to write
00278     * the config file to disk, better riffle thru the data and make sure
00279     * the file names are changed.
00280     */
00281    /* file names are on categories, includes (of course), and on variables. So,
00282     * traverse all this and swap names */
00283 
00284    for (incl = conf->includes; incl; incl=incl->next) {
00285       if (strcmp(incl->include_location_file,from_file) == 0) {
00286          if (from_len >= to_len)
00287             strcpy(incl->include_location_file, to_file);
00288          else {
00289             free(incl->include_location_file);
00290             incl->include_location_file = strdup(to_file);
00291          }
00292       }
00293    }
00294    for (cat = conf->root; cat; cat = cat->next) {
00295       if (strcmp(cat->file,from_file) == 0) {
00296          if (from_len >= to_len)
00297             strcpy(cat->file, to_file);
00298          else {
00299             free(cat->file);
00300             cat->file = strdup(to_file);
00301          }
00302       }
00303       for (v = cat->root; v; v = v->next) {
00304          if (strcmp(v->file,from_file) == 0) {
00305             if (from_len >= to_len)
00306                strcpy(v->file, to_file);
00307             else {
00308                free(v->file);
00309                v->file = strdup(to_file);
00310             }
00311          }
00312       }
00313    }
00314 }

struct ast_variable* ast_load_realtime ( const char *  family,
  ... 
) [read]

Retrieve realtime configuration.

Parameters:
family which 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 that 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.

Definition at line 2072 of file config.c.

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

Referenced by copy_plain_file(), find_conf_realtime(), find_user_realtime(), leave_queue(), load_realtime_queue(), local_ast_moh_start(), queue_function_queuewaitingcount(), realtime_alias(), realtime_peer(), realtime_switch_common(), realtime_user(), and update_realtime_member_field().

02073 {
02074    struct ast_variable *res, *cur, *prev = NULL, *freeme = NULL;
02075    va_list ap;
02076 
02077    va_start(ap, family);
02078    res = ast_load_realtime_helper(family, ap);
02079    va_end(ap);
02080 
02081    /* Eliminate blank entries */
02082    for (cur = res; cur; cur = cur->next) {
02083       if (freeme) {
02084          ast_free(freeme);
02085          freeme = NULL;
02086       }
02087 
02088       if (ast_strlen_zero(cur->value)) {
02089          if (prev)
02090             prev->next = cur->next;
02091          else
02092             res = cur->next;
02093          freeme = cur;
02094       } else {
02095          prev = cur;
02096       }
02097    }
02098    return res;
02099 }

struct ast_variable* ast_load_realtime_all ( const char *  family,
  ... 
) [read]

Definition at line 2060 of file config.c.

References ast_load_realtime_helper().

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

02061 {
02062    struct ast_variable *res;
02063    va_list ap;
02064 
02065    va_start(ap, family);
02066    res = ast_load_realtime_helper(family, ap);
02067    va_end(ap);
02068 
02069    return res;
02070 }

struct ast_config* ast_load_realtime_multientry ( const char *  family,
  ... 
) [read]

Retrieve realtime configuration.

Parameters:
family which 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 taditional ast_config structure rather than just returning a linked list of variables.

Definition at line 2118 of file config.c.

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

Referenced by __queues_show(), load_realtime_queue(), realtime_directory(), realtime_peer(), realtime_switch_common(), show_users_realtime(), and update_realtime_members().

02119 {
02120    struct ast_config_engine *eng;
02121    char db[256]="";
02122    char table[256]="";
02123    struct ast_config *res=NULL;
02124    va_list ap;
02125 
02126    va_start(ap, family);
02127    eng = find_engine(family, db, sizeof(db), table, sizeof(table));
02128    if (eng && eng->realtime_multi_func) 
02129       res = eng->realtime_multi_func(db, table, ap);
02130    va_end(ap);
02131 
02132    return res;
02133 }

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

The argument parsing routine.

Parameters:
arg the string to parse. It is not modified.
flags combination of ast_parse_flags to specify the return type and additional checks.
result pointer 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:
0 in case of success, != 0 otherwise.
result returns 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

Definition at line 2187 of file config.c.

References ast_debug, ast_gethostbyname(), ast_inet_ntoa(), ast_strdupa, buf, hp, 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, and strsep().

Referenced by ast_sip_ouraddrfor(), check_via_response(), and reload_config().

02189 {
02190    va_list ap;
02191    int error = 0;
02192 
02193    va_start(ap, p_result);
02194    switch (flags & PARSE_TYPE) {
02195    case PARSE_INT32:
02196        {
02197       int32_t *result = p_result;
02198       int32_t x, def = result ? *result : 0,
02199          high = (int32_t)0x7fffffff,
02200          low  = (int32_t)0x80000000;
02201       /* optional argument: first default value, then range */
02202       if (flags & PARSE_DEFAULT)
02203          def = va_arg(ap, int32_t);
02204       if (flags & (PARSE_IN_RANGE|PARSE_OUT_RANGE)) {
02205          /* range requested, update bounds */
02206          low = va_arg(ap, int32_t);
02207          high = va_arg(ap, int32_t);
02208       }
02209       x = strtol(arg, NULL, 0);
02210       error = (x < low) || (x > high);
02211       if (flags & PARSE_OUT_RANGE)
02212          error = !error;
02213       if (result)
02214          *result  = error ? def : x;
02215       ast_debug(3,
02216          "extract int from [%s] in [%d, %d] gives [%d](%d)\n",
02217          arg, low, high,
02218          result ? *result : x, error);
02219       break;
02220        }
02221 
02222    case PARSE_UINT32:
02223        {
02224       uint32_t *result = p_result;
02225       uint32_t x, def = result ? *result : 0,
02226          low = 0, high = (uint32_t)~0;
02227       /* optional argument: first default value, then range */
02228       if (flags & PARSE_DEFAULT)
02229          def = va_arg(ap, uint32_t);
02230       if (flags & (PARSE_IN_RANGE|PARSE_OUT_RANGE)) {
02231          /* range requested, update bounds */
02232          low = va_arg(ap, uint32_t);
02233          high = va_arg(ap, uint32_t);
02234       }
02235       x = strtoul(arg, NULL, 0);
02236       error = (x < low) || (x > high);
02237       if (flags & PARSE_OUT_RANGE)
02238          error = !error;
02239       if (result)
02240          *result  = error ? def : x;
02241       ast_debug(3,
02242          "extract uint from [%s] in [%u, %u] gives [%u](%d)\n",
02243          arg, low, high,
02244          result ? *result : x, error);
02245       break;
02246        }
02247 
02248    case PARSE_DOUBLE:
02249        {
02250       double *result = p_result;
02251       double x, def = result ? *result : 0,
02252          low = -HUGE_VAL, high = HUGE_VAL;
02253 
02254       /* optional argument: first default value, then range */
02255       if (flags & PARSE_DEFAULT)
02256          def = va_arg(ap, double);
02257       if (flags & (PARSE_IN_RANGE|PARSE_OUT_RANGE)) {
02258          /* range requested, update bounds */
02259          low = va_arg(ap, double);
02260          high = va_arg(ap, double);
02261       }
02262       x = strtod(arg, NULL);
02263       error = (x < low) || (x > high);
02264       if (flags & PARSE_OUT_RANGE)
02265          error = !error;
02266       if (result)
02267          *result  = error ? def : x;
02268       ast_debug(3,
02269          "extract double from [%s] in [%f, %f] gives [%f](%d)\n",
02270          arg, low, high,
02271          result ? *result : x, error);
02272       break;
02273        }
02274    case PARSE_INADDR:
02275        {
02276       char *port, *buf;
02277       struct sockaddr_in _sa_buf;   /* buffer for the result */
02278       struct sockaddr_in *sa = p_result ?
02279          (struct sockaddr_in *)p_result : &_sa_buf;
02280       /* default is either the supplied value or the result itself */
02281       struct sockaddr_in *def = (flags & PARSE_DEFAULT) ?
02282          va_arg(ap, struct sockaddr_in *) : sa;
02283       struct hostent *hp;
02284       struct ast_hostent ahp;
02285 
02286       memset(&_sa_buf, '\0', sizeof(_sa_buf)); /* clear buffer */
02287       /* duplicate the string to strip away the :port */
02288       port = ast_strdupa(arg);
02289       buf = strsep(&port, ":");
02290       sa->sin_family = AF_INET;  /* assign family */
02291       /*
02292        * honor the ports flag setting, assign default value
02293        * in case of errors or field unset.
02294        */
02295       flags &= PARSE_PORT_MASK; /* the only flags left to process */
02296       if (port) {
02297          if (flags == PARSE_PORT_FORBID) {
02298             error = 1;  /* port was forbidden */
02299             sa->sin_port = def->sin_port;
02300          } else if (flags == PARSE_PORT_IGNORE)
02301             sa->sin_port = def->sin_port;
02302          else /* accept or require */
02303             sa->sin_port = htons(strtol(port, NULL, 0));
02304       } else {
02305          sa->sin_port = def->sin_port;
02306          if (flags == PARSE_PORT_REQUIRE)
02307             error = 1;
02308       }
02309       /* Now deal with host part, even if we have errors before. */
02310       hp = ast_gethostbyname(buf, &ahp);
02311       if (hp)  /* resolved successfully */
02312          memcpy(&sa->sin_addr, hp->h_addr, sizeof(sa->sin_addr));
02313       else {
02314          error = 1;
02315          sa->sin_addr = def->sin_addr;
02316       }
02317       ast_debug(3,
02318          "extract inaddr from [%s] gives [%s:%d](%d)\n",
02319          arg, ast_inet_ntoa(sa->sin_addr),
02320          ntohs(sa->sin_port), error);
02321          break;
02322        }
02323    }
02324    va_end(ap);
02325    return error;
02326 }

int ast_realtime_enabled ( void   ) 

Check if there's any realtime engines loaded.

Definition at line 2113 of file config.c.

References config_maps.

Referenced by action_coresettings(), and handle_show_settings().

02114 {
02115    return config_maps ? 1 : 0;
02116 }

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

Create realtime configuration.

Parameters:
family which 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. On the MySQL engine only, for reasons of backwards compatibility, the return value is the insert ID. This value is nonportable and may be changed in a future version to match the other engines.

Definition at line 2152 of file config.c.

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

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

02152                                                 {
02153    struct ast_config_engine *eng;
02154    int res = -1;
02155    char db[256]="";
02156    char table[256]="";
02157    va_list ap;
02158 
02159    va_start(ap, family);
02160    eng = find_engine(family, db, sizeof(db), table, sizeof(table));
02161    if (eng && eng->store_func) 
02162       res = eng->store_func(db, table, ap);
02163    va_end(ap);
02164 
02165    return res;
02166 }

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

Update realtime configuration.

Parameters:
family which family/config to be updated
keyfield which field to use as the key
lookup which 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.

Definition at line 2135 of file config.c.

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

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

02136 {
02137    struct ast_config_engine *eng;
02138    int res = -1;
02139    char db[256]="";
02140    char table[256]="";
02141    va_list ap;
02142 
02143    va_start(ap, lookup);
02144    eng = find_engine(family, db, sizeof(db), table, sizeof(table));
02145    if (eng && eng->update_func) 
02146       res = eng->update_func(db, table, keyfield, lookup, ap);
02147    va_end(ap);
02148 
02149    return res;
02150 }

void ast_variable_append ( struct ast_category category,
struct ast_variable variable 
)

Definition at line 327 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(), and vm_change_password().

00328 {
00329    if (!variable)
00330       return;
00331    if (category->last)
00332       category->last->next = variable;
00333    else
00334       category->root = variable;
00335    category->last = variable;
00336    while (category->last->next)
00337       category->last = category->last->next;
00338 }

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

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

Return values:
ast_variable list on success
NULL on failure

Definition at line 373 of file config.c.

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

Referenced by __ast_http_load(), __init_manager(), action_getconfig(), action_getconfigjson(), adsi_load(), aji_load_config(), ast_readconfig(), ast_variable_retrieve(), build_device(), collect_function_digits(), conf_exec(), config_module(), do_say(), find_conf(), gtalk_load_config(), handle_cli_dialplan_save(), iax_template_parse(), ind_load_module(), init_logger_chain(), jingle_load_config(), load_config(), load_module(), load_modules(), load_moh_classes(), load_odbc_config(), load_rpt_vars(), misdn_cfg_init(), odbc_load_module(), osp_create_provider(), parse_config(), pbx_load_config(), private_enum_init(), read_agent_config(), read_config_maps(), reload(), reload_config(), reload_followme(), reload_queue_rules(), reload_queues(), run_startup_commands(), search_directory(), set_config(), setup_dahdi(), show_users_realtime(), sip_notify(), sla_build_station(), sla_build_trunk(), smdi_load(), store_config(), and tds_load_module().

00374 {
00375    struct ast_category *cat = NULL;
00376 
00377    if (category && config->last_browse && (config->last_browse->name == category))
00378       cat = config->last_browse;
00379    else
00380       cat = ast_category_get(config, category);
00381 
00382    return (cat) ? cat->root : NULL;
00383 }

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

Definition at line 657 of file config.c.

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

Referenced by handle_updates().

00658 {
00659    struct ast_variable *cur, *prev=NULL, *curn;
00660    int res = -1;
00661    int lineno = 0;
00662 
00663    cur = category->root;
00664    while (cur) {
00665       if (cur->name == variable) {
00666          if (prev) {
00667             prev->next = cur->next;
00668             if (cur == category->last)
00669                category->last = prev;
00670          } else {
00671             category->root = cur->next;
00672             if (cur == category->last)
00673                category->last = NULL;
00674          }
00675          cur->next = NULL;
00676          ast_variables_destroy(cur);
00677          return 0;
00678       }
00679       prev = cur;
00680       cur = cur->next;
00681    }
00682 
00683    prev = NULL;
00684    cur = category->root;
00685    while (cur) {
00686       curn = cur->next;
00687       if ((!ast_strlen_zero(line) && lineno == atoi(line)) || (ast_strlen_zero(line) && !strcasecmp(cur->name, variable) && (ast_strlen_zero(match) || !strcasecmp(cur->value, match)))) {
00688          if (prev) {
00689             prev->next = cur->next;
00690             if (cur == category->last)
00691                category->last = prev;
00692          } else {
00693             category->root = cur->next;
00694             if (cur == category->last)
00695                category->last = NULL;
00696          }
00697          cur->next = NULL;
00698          ast_variables_destroy(cur);
00699          res = 0;
00700       } else
00701          prev = cur;
00702 
00703       cur = curn;
00704       lineno++;
00705    }
00706    return res;
00707 }

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

Definition at line 340 of file config.c.

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

Referenced by handle_updates().

00341 {
00342    struct ast_variable *cur = category->root;
00343    int lineno;
00344    int insertline;
00345 
00346    if (!variable || sscanf(line, "%30d", &insertline) != 1)
00347       return;
00348    if (!insertline) {
00349       variable->next = category->root;
00350       category->root = variable;
00351    } else {
00352       for (lineno = 1; lineno < insertline; lineno++) {
00353          cur = cur->next;
00354          if (!cur->next)
00355             break;
00356       }
00357       variable->next = cur->next;
00358       cur->next = variable;
00359    }
00360 }

struct ast_variable* ast_variable_new ( const char *  name,
const char *  value,
const char *  filename 
) [read]

Definition at line 207 of file config.c.

References ast_calloc, ast_variable::file, 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_variable_update(), astman_get_variables(), build_user(), check_access(), config_curl(), config_ldap(), config_odbc(), config_pgsql(), copy_vars(), create_vmaccount(), handle_updates(), handle_uri(), httpd_helper_thread(), iax_parse_ies(), ldap_table_config_add_attribute(), 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(), variable_clone(), and vm_change_password().

00208 {
00209    struct ast_variable *variable;
00210    int name_len = strlen(name) + 1; 
00211    int val_len = strlen(value) + 1; 
00212    int fn_len = strlen(filename) + 1;  
00213 
00214    if ((variable = ast_calloc(1, name_len + val_len + fn_len + sizeof(*variable)))) {
00215       char *dst = variable->stuff;  /* writable space starts here */
00216       variable->name = strcpy(dst, name);
00217       dst += name_len;
00218       variable->value = strcpy(dst, value);
00219       dst += val_len;
00220       variable->file = strcpy(dst, filename);
00221    }
00222    return variable;
00223 }

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

Gets a variable.

Parameters:
config which (opened) config to use
category category under which the variable lies
variable which 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:
The variable value on success
NULL if unable to find it.

Definition at line 395 of file config.c.

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

Referenced by __ast_rtp_reload(), __ast_udptl_reload(), __init_manager(), advanced_options(), aji_load_config(), ast_config_option(), attempt_reconnect(), build_user(), config_module(), directory_exec(), do_reload(), festival_exec(), find_queue_by_name_rt(), function_gosub(), function_ilink(), function_macro(), function_remote(), get_insecure_variable_from_config(), get_wait_interval(), gtalk_load_config(), iax_template_parse(), ind_load_module(), init_acf_query(), init_logger_chain(), jingle_load_config(), load_config(), load_config_meetme(), load_module(), load_modules(), 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(), realtime_directory(), reload_config(), reload_followme(), reload_queues(), retrieve_astcfgint(), rpt(), rpt_exec(), rpt_master(), rpt_tele_thread(), search_directory(), set_config(), setup_dahdi(), sla_build_station(), sla_build_trunk(), sla_load_config(), tds_load_module(), telem_lookup(), update_realtime_members(), vm_change_password(), and vm_forwardoptions().

00396 {
00397    struct ast_variable *v;
00398 
00399    if (category) {
00400       for (v = ast_variable_browse(config, category); v; v = v->next) {
00401          if (!strcasecmp(variable, v->name))
00402             return v->value;
00403       }
00404    } else {
00405       struct ast_category *cat;
00406 
00407       for (cat = config->root; cat; cat = cat->next)
00408          for (v = cat->root; v; v = v->next)
00409             if (!strcasecmp(variable, v->name))
00410                return v->value;
00411    }
00412 
00413    return NULL;
00414 }

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

Definition at line 709 of file config.c.

References ast_strlen_zero(), ast_variable_new(), ast_variables_destroy(), ast_variable::blanklines, ast_variable::file, ast_category::last, ast_variable::lineno, ast_variable::name, ast_variable::next, ast_variable::object, ast_variable::precomments, ast_category::root, ast_variable::sameline, ast_variable::trailing, and ast_variable::value.

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

00711 {
00712    struct ast_variable *cur, *prev=NULL, *newer=NULL;
00713 
00714    for (cur = category->root; cur; prev = cur, cur = cur->next) {
00715       if (strcasecmp(cur->name, variable) ||
00716          (!ast_strlen_zero(match) && strcasecmp(cur->value, match)))
00717          continue;
00718 
00719       if (!(newer = ast_variable_new(variable, value, cur->file)))
00720          return -1;
00721    
00722       newer->next = cur->next;
00723       newer->object = cur->object || object;
00724 
00725       /* Preserve everything */
00726       newer->lineno = cur->lineno;
00727       newer->blanklines = cur->blanklines;
00728       newer->precomments = cur->precomments; cur->precomments = NULL;
00729       newer->sameline = cur->sameline; cur->sameline = NULL;
00730       newer->trailing = cur->trailing; cur->trailing = NULL;
00731 
00732       if (prev)
00733          prev->next = newer;
00734       else
00735          category->root = newer;
00736       if (category->last == cur)
00737          category->last = newer;
00738 
00739       cur->next = NULL;
00740       ast_variables_destroy(cur);
00741 
00742       return 0;
00743    }
00744 
00745    if (prev)
00746       prev->next = newer;
00747    else
00748       category->root = newer;
00749 
00750    return 0;
00751 }

void ast_variables_destroy ( struct ast_variable var  ) 

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

Definition at line 1550 of file config.c.

References ao2_container_alloc(), ao2_ref(), ast_debug, AST_LIST_EMPTY, AST_LIST_LAST, AST_LIST_TRAVERSE, 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, ast_variable::name, ast_category_template_instance::name, ast_category::name, ast_category::next, ast_variable::next, ast_comment::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(), vm_change_password(), and vm_forwardoptions().

01551 {
01552    FILE *f;
01553    char fn[256];
01554    struct ast_variable *var;
01555    struct ast_category *cat;
01556    struct ast_comment *cmt;
01557    struct ast_config_include *incl;
01558    int blanklines = 0;
01559    struct ao2_container *fileset = ao2_container_alloc(180000, hash_string, hashtab_compare_strings);
01560    struct inclfile *fi = 0;
01561 
01562    /* reset all the output flags, in case this isn't our first time saving this data */
01563 
01564    for (incl=cfg->includes; incl; incl = incl->next)
01565       incl->output = 0;
01566 
01567    /* go thru all the inclusions and make sure all the files involved (configfile plus all its inclusions)
01568       are all truncated to zero bytes and have that nice header*/
01569 
01570    for (incl=cfg->includes; incl; incl = incl->next)
01571    {
01572       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*/
01573          FILE *f1;
01574 
01575          set_fn(fn, sizeof(fn), incl->included_file, configfile, fileset, &fi); /* normally, fn is just set to incl->included_file, prepended with config dir if relative */
01576          f1 = fopen(fn,"w");
01577          if (f1) {
01578             gen_header(f1, configfile, fn, generator);
01579             fclose(f1); /* this should zero out the file */
01580          } else {
01581             ast_debug(1, "Unable to open for writing: %s\n", fn);
01582             ast_verb(2, "Unable to write %s (%s)", fn, strerror(errno));
01583          }
01584          ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */
01585          fi = 0;
01586       }
01587    }
01588 
01589    set_fn(fn, sizeof(fn), 0, configfile, fileset, &fi); /* just set fn to absolute ver of configfile */
01590 #ifdef __CYGWIN__ 
01591    if ((f = fopen(fn, "w+"))) {
01592 #else
01593    if ((f = fopen(fn, "w"))) {
01594 #endif       
01595       ast_verb(2, "Saving '%s': ", fn);
01596       gen_header(f, configfile, fn, generator);
01597       cat = cfg->root;
01598       fclose(f);
01599       ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */
01600       
01601       /* from here out, we open each involved file and concat the stuff we need to add to the end and immediately close... */
01602       /* since each var, cat, and associated comments can come from any file, we have to be 
01603          mobile, and open each file, print, and close it on an entry-by-entry basis */
01604 
01605       while (cat) {
01606          set_fn(fn, sizeof(fn), cat->file, configfile, fileset, &fi);
01607          f = fopen(fn, "a");
01608          if (!f)
01609          {
01610             ast_debug(1, "Unable to open for writing: %s\n", fn);
01611             ast_verb(2, "Unable to write %s (%s)", fn, strerror(errno));
01612             ao2_ref(fileset, -1);
01613             return -1;
01614          }
01615 
01616          /* dump any includes that happen before this category header */
01617          for (incl=cfg->includes; incl; incl = incl->next) {
01618             if (strcmp(incl->include_location_file, cat->file) == 0){
01619                if (cat->lineno > incl->include_location_lineno && !incl->output) {
01620                   if (incl->exec)
01621                      fprintf(f,"#exec \"%s\"\n", incl->exec_file);
01622                   else
01623                      fprintf(f,"#include \"%s\"\n", incl->included_file);
01624                   incl->output = 1;
01625                }
01626             }
01627          }
01628 
01629          insert_leading_blank_lines(f, fi, cat->precomments, cat->lineno);
01630          /* Dump section with any appropriate comment */
01631          for (cmt = cat->precomments; cmt; cmt=cmt->next) {
01632             char *cmtp = cmt->cmt;
01633             while (*cmtp == ';' && *(cmtp+1) == '!') {
01634                char *cmtp2 = strchr(cmtp+1, '\n');
01635                if (cmtp2)
01636                   cmtp = cmtp2+1;
01637                else cmtp = 0;
01638             }
01639             if (cmtp)
01640                fprintf(f,"%s", cmtp);
01641          }
01642          fprintf(f, "[%s]", cat->name);
01643          if (cat->ignored || !AST_LIST_EMPTY(&cat->template_instances)) {
01644             fprintf(f, "(");
01645             if (cat->ignored) {
01646                fprintf(f, "!");
01647             }
01648             if (cat->ignored && !AST_LIST_EMPTY(&cat->template_instances)) {
01649                fprintf(f, ",");
01650             }
01651             if (!AST_LIST_EMPTY(&cat->template_instances)) {
01652                struct ast_category_template_instance *x;
01653                AST_LIST_TRAVERSE(&cat->template_instances, x, next) {
01654                   fprintf(f,"%s",x->name);
01655                   if (x != AST_LIST_LAST(&cat->template_instances))
01656                      fprintf(f,",");
01657                }
01658             }
01659             fprintf(f, ")");
01660          }
01661          for(cmt = cat->sameline; cmt; cmt=cmt->next)
01662          {
01663             fprintf(f,"%s", cmt->cmt);
01664          }
01665          if (!cat->sameline)
01666             fprintf(f,"\n");
01667          for (cmt = cat->trailing; cmt; cmt=cmt->next) {
01668             if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
01669                fprintf(f,"%s", cmt->cmt);
01670          }
01671          fclose(f);
01672          ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */
01673          fi = 0;
01674          
01675          var = cat->root;
01676          while (var) {
01677             struct ast_category_template_instance *x;
01678             int found = 0;
01679             AST_LIST_TRAVERSE(&cat->template_instances, x, next) {
01680                struct ast_variable *v;
01681                for (v = x->inst->root; v; v = v->next) {
01682                   if (!strcasecmp(var->name, v->name) && !strcmp(var->value, v->value)) {
01683                      found = 1;
01684                      break;
01685                   }
01686                }
01687                if (found)
01688                   break;
01689             }
01690             if (found) {
01691                var = var->next;
01692                continue;
01693             }
01694             set_fn(fn, sizeof(fn), var->file, configfile, fileset, &fi);
01695             f = fopen(fn, "a");
01696             if (!f)
01697             {
01698                ast_debug(1, "Unable to open for writing: %s\n", fn);
01699                ast_verb(2, "Unable to write %s (%s)", fn, strerror(errno));
01700                ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */
01701                fi = 0;
01702                ao2_ref(fileset, -1);
01703                return -1;
01704             }
01705             
01706             /* dump any includes that happen before this category header */
01707             for (incl=cfg->includes; incl; incl = incl->next) {
01708                if (strcmp(incl->include_location_file, var->file) == 0){
01709                   if (var->lineno > incl->include_location_lineno && !incl->output) {
01710                      if (incl->exec)
01711                         fprintf(f,"#exec \"%s\"\n", incl->exec_file);
01712                      else
01713                         fprintf(f,"#include \"%s\"\n", incl->included_file);
01714                      incl->output = 1;
01715                   }
01716                }
01717             }
01718             
01719             insert_leading_blank_lines(f, fi, var->precomments, var->lineno);
01720             for (cmt = var->precomments; cmt; cmt=cmt->next) {
01721                if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
01722                   fprintf(f,"%s", cmt->cmt);
01723             }
01724             if (var->sameline) 
01725                fprintf(f, "%s %s %s  %s", var->name, (var->object ? "=>" : "="), var->value, var->sameline->cmt);
01726             else  
01727                fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="), var->value);
01728             for (cmt = var->trailing; cmt; cmt=cmt->next) {
01729                if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
01730                   fprintf(f,"%s", cmt->cmt);
01731             }
01732             if (var->blanklines) {
01733                blanklines = var->blanklines;
01734                while (blanklines--)
01735                   fprintf(f, "\n");
01736             }
01737             
01738             fclose(f);
01739             ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */
01740             fi = 0;
01741             
01742             var = var->next;
01743          }
01744          cat = cat->next;
01745       }
01746       if (!option_debug)
01747          ast_verb(2, "Saved\n");
01748    } else {
01749       ast_debug(1, "Unable to open for writing: %s\n", fn);
01750       ast_verb(2, "Unable to write (%s)", strerror(errno));
01751       ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */
01752       ao2_ref(fileset, -1);
01753       return -1;
01754    }
01755 
01756    /* Now, for files with trailing #include/#exec statements,
01757       we have to make sure every entry is output */
01758 
01759    for (incl=cfg->includes; incl; incl = incl->next) {
01760       if (!incl->output) {
01761          /* open the respective file */
01762          set_fn(fn, sizeof(fn), incl->include_location_file, configfile, fileset, &fi);
01763          f = fopen(fn, "a");
01764          if (!f)
01765          {
01766             ast_debug(1, "Unable to open for writing: %s\n", fn);
01767             ast_verb(2, "Unable to write %s (%s)", fn, strerror(errno));
01768             ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */
01769             fi = 0;
01770             ao2_ref(fileset, -1);
01771             return -1;
01772          }
01773          
01774          /* output the respective include */
01775          if (incl->exec)
01776             fprintf(f,"#exec \"%s\"\n", incl->exec_file);
01777          else
01778             fprintf(f,"#include \"%s\"\n", incl->included_file);
01779          fclose(f);
01780          incl->output = 1;
01781          ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */
01782          fi = 0;
01783       }
01784    }
01785    ao2_ref(fileset, -1); /* this should destroy the hash container */
01786             
01787    return 0;
01788 }

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 1838 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(), buf, clear_config_maps(), config, LOG_WARNING, ast_config::max_include_level, ast_variable::name, ast_variable::next, strsep(), table, and ast_variable::value.

Referenced by main().

01839 {
01840    struct ast_config *config, *configtmp;
01841    struct ast_variable *v;
01842    char *driver, *table, *database, *stringp, *tmp;
01843    struct ast_flags flags = { 0 };
01844 
01845    clear_config_maps();
01846 
01847    configtmp = ast_config_new();
01848    configtmp->max_include_level = 1;
01849    config = ast_config_internal_load(extconfig_conf, configtmp, flags, "", "config.c");
01850    if (!config) {
01851       ast_config_destroy(configtmp);
01852       return 0;
01853    }
01854 
01855    for (v = ast_variable_browse(config, "settings"); v; v = v->next) {
01856       char buf[512];
01857       ast_copy_string(buf, v->value, sizeof(buf));
01858       stringp = buf;
01859       driver = strsep(&stringp, ",");
01860 
01861       if ((tmp = strchr(stringp, '\"')))
01862          stringp = tmp;
01863 
01864       /* check if the database text starts with a double quote */
01865       if (*stringp == '"') {
01866          stringp++;
01867          database = strsep(&stringp, "\"");
01868          strsep(&stringp, ",");
01869       } else {
01870          /* apparently this text has no quotes */
01871          database = strsep(&stringp, ",");
01872       }
01873 
01874       table = strsep(&stringp, ",");
01875 
01876       if (!strcmp(v->name, extconfig_conf)) {
01877          ast_log(LOG_WARNING, "Cannot bind '%s'!\n", extconfig_conf);
01878          continue;
01879       }
01880 
01881       if (!strcmp(v->name, "asterisk.conf")) {
01882          ast_log(LOG_WARNING, "Cannot bind 'asterisk.conf'!\n");
01883          continue;
01884       }
01885 
01886       if (!strcmp(v->name, "logger.conf")) {
01887          ast_log(LOG_WARNING, "Cannot bind 'logger.conf'!\n");
01888          continue;
01889       }
01890 
01891       if (!driver || !database)
01892          continue;
01893       if (!strcasecmp(v->name, "sipfriends")) {
01894          ast_log(LOG_WARNING, "The 'sipfriends' table is obsolete, update your config to use sipusers and sippeers, though they can point to the same table.\n");
01895          append_mapping("sipusers", driver, database, table ? table : "sipfriends");
01896          append_mapping("sippeers", driver, database, table ? table : "sipfriends");
01897       } else if (!strcasecmp(v->name, "iaxfriends")) {
01898          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");
01899          append_mapping("iaxusers", driver, database, table ? table : "iaxfriends");
01900          append_mapping("iaxpeers", driver, database, table ? table : "iaxfriends");
01901       } else 
01902          append_mapping(v->name, driver, database, table);
01903    }
01904       
01905    ast_config_destroy(config);
01906    return 0;
01907 }

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

References ast_cli_register_multiple().

Referenced by main().

02372 {
02373    ast_cli_register_multiple(cli_config, sizeof(cli_config) / sizeof(struct ast_cli_entry));
02374    return 0;
02375 }


Generated on Wed Oct 28 11:46:07 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6