Wed Mar 3 22:53:05 2010

Asterisk developer's documentation


config.h File Reference

Configuration File Parser. More...

#include "asterisk/utils.h"
#include "asterisk/inline_api.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, AST_MODULE, 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_require (const char *database, const char *table, va_list ap)
 Function pointer called to ensure database schema is properly configured for realtime use.
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.
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...
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.
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,...) attribute_sentinel
 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,...) attribute_sentinel
 Retrieve realtime configuration.
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.
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_realtime_require_field (const char *family,...) attribute_sentinel
 Inform realtime what fields that may be stored.
int ast_store_realtime (const char *family,...) attribute_sentinel
 Create realtime configuration.
int ast_unload_realtime (const char *family)
 Release any resources cached for a realtime family.
int ast_update_realtime (const char *family, const char *keyfield, const char *lookup,...) attribute_sentinel
 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)
 Update variable value within a config.
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, AST_MODULE, 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 552 of file config.h.

Referenced by store_config_core().

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

Definition at line 555 of file config.h.

#define CV_END   } while (0)

close a variable parsing block

Definition at line 544 of file config.h.

Referenced by 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 547 of file config.h.

Referenced by 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 538 of file config.h.

Referenced by store_config_core().

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

Definition at line 554 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 556 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 553 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 88 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 93 of file config.h.

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

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

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

Definition at line 92 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 105 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 91 of file config.h.

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

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

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

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

00443                      {
00444    /* low 4 bits of flags are used for the operand type */
00445    PARSE_TYPE  =  0x000f,
00446    /* numeric types, with optional default value and bound checks.
00447     * Additional arguments are passed by value.
00448     */
00449    PARSE_INT32 =  0x0001,
00450    PARSE_UINT32   =  0x0002,
00451    PARSE_DOUBLE   =  0x0003,
00452 #if 0 /* not supported yet */
00453    PARSE_INT16 =  0x0004,
00454    PARSE_UINT16   =  0x0005,
00455 #endif
00456    /* Returns a struct sockaddr_in, with optional default value
00457     * (passed by reference) and port handling (accept, ignore,
00458     * require, forbid). The format is 'host.name[:port]'
00459     */
00460    PARSE_INADDR   =  0x000f,
00461 
00462    /* Other data types can be added as needed */
00463 
00464    /* If PARSE_DEFAULT is set, next argument is a default value
00465     * which is returned in case of error. The argument is passed
00466     * by value in case of numeric types, by reference in other cases.
00467     */
00468    PARSE_DEFAULT  =  0x0010,  /* assign default on error */
00469 
00470    /* Request a range check, applicable to numbers. Two additional
00471     * arguments are passed by value, specifying the low-high end of
00472     * the range (inclusive). An error is returned if the value
00473     * is outside or inside the range, respectively.
00474     */
00475    PARSE_IN_RANGE =  0x0020,  /* accept values inside a range */
00476    PARSE_OUT_RANGE = 0x0040,  /* accept values outside a range */
00477 
00478    /* Port handling, for sockaddr_in. accept/ignore/require/forbid
00479     * port number after the hostname or address.
00480     */
00481    PARSE_PORT_MASK = 0x0300, /* 0x000: accept port if present */
00482    PARSE_PORT_IGNORE =  0x0100, /* 0x100: ignore port if present */
00483    PARSE_PORT_REQUIRE = 0x0200, /* 0x200: require port number */
00484    PARSE_PORT_FORBID =  0x0300, /* 0x100: forbid port number */
00485 };

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

00053              {
00054    RQ_INTEGER1,
00055    RQ_UINTEGER1,
00056    RQ_INTEGER2,
00057    RQ_UINTEGER2,
00058    RQ_INTEGER3,
00059    RQ_UINTEGER3,
00060    RQ_INTEGER4,
00061    RQ_UINTEGER4,
00062    RQ_INTEGER8,
00063    RQ_UINTEGER8,
00064    RQ_CHAR,
00065    RQ_FLOAT,
00066    RQ_DATE,
00067    RQ_DATETIME,
00068 } require_type;


Function Documentation

void ast_category_append ( struct ast_config config,
struct ast_category cat 
)

Definition at line 494 of file config.c.

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

00495 {
00496    if (config->last)
00497       config->last->next = category;
00498    else
00499       config->root = category;
00500    category->include_level = config->include_level;
00501    config->last = category;
00502    config->current = category;
00503 }

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

References ast_config::last_browse, ast_category::name, 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().

00605 {  
00606    struct ast_category *cat = NULL;
00607 
00608    if (prev && config->last_browse && (config->last_browse->name == prev))
00609       cat = config->last_browse->next;
00610    else if (!prev && config->root)
00611       cat = config->root;
00612    else if (prev) {
00613       for (cat = config->root; cat; cat = cat->next) {
00614          if (cat->name == prev) {
00615             cat = cat->next;
00616             break;
00617          }
00618       }
00619       if (!cat) {
00620          for (cat = config->root; cat; cat = cat->next) {
00621             if (!strcasecmp(cat->name, prev)) {
00622                cat = cat->next;
00623                break;
00624             }
00625          }
00626       }
00627    }
00628    
00629    if (cat)
00630       cat = next_available_category(cat);
00631 
00632    config->last_browse = cat;
00633    return (cat) ? cat->name : NULL;
00634 }

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

Definition at line 765 of file config.c.

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

Referenced by handle_updates().

00766 {
00767    struct ast_category *prev=NULL, *cat;
00768 
00769    cat = cfg->root;
00770    while (cat) {
00771       if (cat->name == category) {
00772          if (prev) {
00773             prev->next = cat->next;
00774             if (cat == cfg->last)
00775                cfg->last = prev;
00776          } else {
00777             cfg->root = cat->next;
00778             if (cat == cfg->last)
00779                cfg->last = NULL;
00780          }
00781          ast_category_destroy(cat);
00782          return 0;
00783       }
00784       prev = cat;
00785       cat = cat->next;
00786    }
00787 
00788    prev = NULL;
00789    cat = cfg->root;
00790    while (cat) {
00791       if (!strcasecmp(cat->name, category)) {
00792          if (prev) {
00793             prev->next = cat->next;
00794             if (cat == cfg->last)
00795                cfg->last = prev;
00796          } else {
00797             cfg->root = cat->next;
00798             if (cat == cfg->last)
00799                cfg->last = NULL;
00800          }
00801          ast_category_destroy(cat);
00802          return 0;
00803       }
00804       prev = cat;
00805       cat = cat->next;
00806    }
00807    return -1;
00808 }

void ast_category_destroy ( struct ast_category cat  ) 

Definition at line 554 of file config.c.

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

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

00555 {
00556    ast_variables_destroy(cat->root);
00557    if (cat->file) {
00558       free(cat->file);
00559       cat->file = 0;
00560    }
00561    ast_destroy_comments(cat);
00562    ast_destroy_template_list(cat);
00563    ast_free(cat);
00564 }

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

Definition at line 636 of file config.c.

Referenced by realtime_switch_common().

00637 {
00638    struct ast_variable *v;
00639 
00640    v = cat->root;
00641    cat->root = NULL;
00642    cat->last = NULL;
00643 
00644    return v;
00645 }

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

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

Referenced by handle_updates().

00811 {
00812    struct ast_category *cat;
00813 
00814    for (cat = cfg->root; cat; cat = cat->next) {
00815       if (!strcasecmp(cat->name, category))
00816          continue;
00817       ast_variables_destroy(cat->root);
00818       cat->root = NULL;
00819       cat->last = NULL;
00820       return 0;
00821    }
00822 
00823    return -1;
00824 }

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

References ast_category_get().

00490 {
00491    return !!ast_category_get(config, category_name);
00492 }

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

Referenced by process_text_line().

00591 {
00592    return (cat) ? cat->root : NULL;
00593 }

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

00485 {
00486    return category_get(config, category_name, 0);
00487 }

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

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

Referenced by handle_updates().

00506 {
00507    struct ast_category *cur_category;
00508 
00509    if (!cat || !match)
00510       return;
00511    if (!strcasecmp(config->root->name, match)) {
00512       cat->next = config->root;
00513       config->root = cat;
00514       return;
00515    } 
00516    for (cur_category = config->root; cur_category; cur_category = cur_category->next) {
00517       if (!strcasecmp(cur_category->next->name, match)) {
00518          cat->next = cur_category->next;
00519          cur_category->next = cat;
00520          break;
00521       }
00522    }
00523 }

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

Create a category structure.

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

00456 {
00457    struct ast_category *category;
00458 
00459    if ((category = ast_calloc(1, sizeof(*category))))
00460       ast_copy_string(category->name, name, sizeof(category->name));
00461    category->file = strdup(in_file);
00462    category->lineno = lineno; /* if you don't know the lineno, set it to 999999 or something real big */
00463    return category;
00464 }

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

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

00648 {
00649    ast_copy_string(cat->name, name, sizeof(cat->name));
00650 }

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

References ast_category_get().

Referenced by get_insecure_variable_from_config().

00596 {
00597    struct ast_category *category = ast_category_get(config, cat);
00598 
00599    if (category)
00600       return category->root;
00601    return NULL;
00602 }

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 2132 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(), load_module(), local_ast_moh_start(), realtime_peer(), realtime_update_peer(), rename_file(), sip_poke_noanswer(), sip_show_settings(), and vm_delete().

02133 {
02134    struct ast_config_engine *eng;
02135 
02136    eng = find_engine(family, NULL, 0, NULL, 0);
02137    if (eng)
02138       return 1;
02139    return 0;
02140 }

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

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

Referenced by __ast_http_load(), __ast_http_post_load(), __ast_rtp_reload(), __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_config_load2(), ast_readconfig(), conf_exec(), config_function_read(), 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(), misdn_cfg_init(), node_lookup(), 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().

00827 {
00828    struct ast_category *cat, *catn;
00829 
00830    if (!cfg)
00831       return;
00832 
00833    ast_includes_destroy(cfg->includes);
00834 
00835    cat = cfg->root;
00836    while (cat) {
00837       catn = cat;
00838       cat = cat->next;
00839       ast_category_destroy(catn);
00840    }
00841    ast_free(cfg);
00842 }

int ast_config_engine_deregister ( struct ast_config_engine del  ) 

Deregister config engine.

Return values:
0 Always

Definition at line 1958 of file config.c.

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

Referenced by unload_module().

01959 {
01960    struct ast_config_engine *ptr, *last=NULL;
01961 
01962    ast_mutex_lock(&config_lock);
01963 
01964    for (ptr = config_engine_list; ptr; ptr=ptr->next) {
01965       if (ptr == del) {
01966          if (last)
01967             last->next = ptr->next;
01968          else
01969             config_engine_list = ptr->next;
01970          break;
01971       }
01972       last = ptr;
01973    }
01974 
01975    ast_mutex_unlock(&config_lock);
01976 
01977    return 0;
01978 }

int ast_config_engine_register ( struct ast_config_engine newconfig  ) 

Register config engine.

Return values:
1 Always

Definition at line 1939 of file config.c.

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

Referenced by load_module().

01940 {
01941    struct ast_config_engine *ptr;
01942 
01943    ast_mutex_lock(&config_lock);
01944 
01945    if (!config_engine_list) {
01946       config_engine_list = new;
01947    } else {
01948       for (ptr = config_engine_list; ptr->next; ptr=ptr->next);
01949       ptr->next = new;
01950    }
01951 
01952    ast_mutex_unlock(&config_lock);
01953    ast_log(LOG_NOTICE,"Registered Config Engine %s\n", new->name);
01954 
01955    return 1;
01956 }

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

References ast_config::current.

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

00845 {
00846    return cfg->current;
00847 }

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

02021 {
02022    char db[256];
02023    char table[256];
02024    struct ast_config_engine *loader = &text_file_engine;
02025    struct ast_config *result; 
02026 
02027    /* The config file itself bumps include_level by 1 */
02028    if (cfg->max_include_level > 0 && cfg->include_level == cfg->max_include_level + 1) {
02029       ast_log(LOG_WARNING, "Maximum Include level (%d) exceeded\n", cfg->max_include_level);
02030       return NULL;
02031    }
02032 
02033    cfg->include_level++;
02034 
02035    if (strcmp(filename, extconfig_conf) && strcmp(filename, "asterisk.conf") && config_engine_list) {
02036       struct ast_config_engine *eng;
02037 
02038       eng = find_engine(filename, db, sizeof(db), table, sizeof(table));
02039 
02040 
02041       if (eng && eng->load_func) {
02042          loader = eng;
02043       } else {
02044          eng = find_engine("global", db, sizeof(db), table, sizeof(table));
02045          if (eng && eng->load_func)
02046             loader = eng;
02047       }
02048    }
02049 
02050    result = loader->load_func(db, table, filename, cfg, flags, suggested_include_file, who_asked);
02051 
02052    if (result && result != CONFIG_STATUS_FILEUNCHANGED)
02053       result->include_level--;
02054    else
02055       cfg->include_level--;
02056 
02057    return result;
02058 }

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

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

Referenced by __ast_http_load(), __ast_http_post_load(), __ast_rtp_reload(), __ast_udptl_reload(), __init_manager(), _dsp_init(), action_getconfig(), action_getconfigjson(), action_listcategories(), action_updateconfig(), ast_readconfig(), do_reload(), iax_provision_reload(), init_logger_chain(), load_config(), load_modules(), misdn_cfg_init(), private_enum_init(), and run_startup_commands().

02061 {
02062    struct ast_config *cfg;
02063    struct ast_config *result;
02064 
02065    cfg = ast_config_new();
02066    if (!cfg)
02067       return NULL;
02068 
02069    result = ast_config_internal_load(filename, cfg, flags, "", who_asked);
02070    if (!result || result == CONFIG_STATUS_FILEUNCHANGED)
02071       ast_config_destroy(cfg);
02072 
02073    return result;
02074 }

struct ast_config* ast_config_new ( void   )  [read]

Create a new base configuration structure.

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

00665 {
00666    struct ast_config *config;
00667 
00668    if ((config = ast_calloc(1, sizeof(*config))))
00669       config->max_include_level = MAX_INCLUDE_LEVEL;
00670    return config;
00671 }

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

References ast_variable_retrieve().

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

00402 {
00403    const char *tmp;
00404    tmp = ast_variable_retrieve(cfg, cat, var);
00405    if (!tmp)
00406       tmp = ast_variable_retrieve(cfg, "general", var);
00407    return tmp;
00408 }

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

References ast_config::current.

00850 {
00851    /* cast below is just to silence compiler warning about dropping "const" */
00852    cfg->current = (struct ast_category *) cat;
00853 }

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

02232 {
02233    struct ast_config_engine *eng;
02234    int res = -1;
02235    char db[256]="";
02236    char table[256]="";
02237    va_list ap;
02238 
02239    va_start(ap, lookup);
02240    eng = find_engine(family, db, sizeof(db), table, sizeof(table));
02241    if (eng && eng->destroy_func) 
02242       res = eng->destroy_func(db, table, keyfield, lookup, ap);
02243    va_end(ap);
02244 
02245    return res;
02246 }

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

Definition at line 332 of file config.c.

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

Referenced by ast_include_new().

00333 {
00334    struct ast_config_include *x;
00335    for (x=conf->includes;x;x=x->next) {
00336       if (strcmp(x->included_file,included_file) == 0)
00337          return x;
00338    }
00339    return 0;
00340 }

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

00242 {
00243    /* a file should be included ONCE. Otherwise, if one of the instances is changed,
00244     * then all be changed. -- how do we know to include it? -- Handling modified 
00245     * instances is possible, I'd have
00246     * to create a new master for each instance. */
00247    struct ast_config_include *inc;
00248    struct stat statbuf;
00249    
00250    inc = ast_include_find(conf, included_file);
00251    if (inc) {
00252       do {
00253          inc->inclusion_count++;
00254          snprintf(real_included_file_name, real_included_file_name_size, "%s~~%d", included_file, inc->inclusion_count);
00255       } while (stat(real_included_file_name, &statbuf) == 0);
00256       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);
00257    } else
00258       *real_included_file_name = 0;
00259    
00260    inc = ast_calloc(1,sizeof(struct ast_config_include));
00261    inc->include_location_file = ast_strdup(from_file);
00262    inc->include_location_lineno = from_lineno;
00263    if (!ast_strlen_zero(real_included_file_name))
00264       inc->included_file = ast_strdup(real_included_file_name);
00265    else
00266       inc->included_file = ast_strdup(included_file);
00267    
00268    inc->exec = is_exec;
00269    if (is_exec)
00270       inc->exec_file = ast_strdup(exec_file);
00271    
00272    /* attach this new struct to the conf struct */
00273    inc->next = conf->includes;
00274    conf->includes = inc;
00275    
00276    return inc;
00277 }

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

Definition at line 279 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_config_include::next, ast_config::root, and strdup.

Referenced by action_updateconfig().

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

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.

Note that you should use the constant SENTINEL to terminate arguments, in order to preserve cross-platform compatibility.

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

02103 {
02104    struct ast_variable *res, *cur, *prev = NULL, *freeme = NULL;
02105    va_list ap;
02106 
02107    va_start(ap, family);
02108    res = ast_load_realtime_helper(family, ap);
02109    va_end(ap);
02110 
02111    /* Eliminate blank entries */
02112    for (cur = res; cur; cur = cur->next) {
02113       if (freeme) {
02114          ast_free(freeme);
02115          freeme = NULL;
02116       }
02117 
02118       if (ast_strlen_zero(cur->value)) {
02119          if (prev)
02120             prev->next = cur->next;
02121          else
02122             res = cur->next;
02123          freeme = cur;
02124       } else {
02125          prev = cur;
02126       }
02127    }
02128    return res;
02129 }

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

Definition at line 2090 of file config.c.

References ast_load_realtime_helper().

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

02091 {
02092    struct ast_variable *res;
02093    va_list ap;
02094 
02095    va_start(ap, family);
02096    res = ast_load_realtime_helper(family, ap);
02097    va_end(ap);
02098 
02099    return res;
02100 }

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 traditional ast_config structure rather than just returning a linked list of variables.

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

02181 {
02182    struct ast_config_engine *eng;
02183    char db[256]="";
02184    char table[256]="";
02185    struct ast_config *res=NULL;
02186    va_list ap;
02187 
02188    va_start(ap, family);
02189    eng = find_engine(family, db, sizeof(db), table, sizeof(table));
02190    if (eng && eng->realtime_multi_func) 
02191       res = eng->realtime_multi_func(db, table, ap);
02192    va_end(ap);
02193 
02194    return res;
02195 }

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

02253 {
02254    va_list ap;
02255    int error = 0;
02256 
02257    va_start(ap, p_result);
02258    switch (flags & PARSE_TYPE) {
02259    case PARSE_INT32:
02260        {
02261       int32_t *result = p_result;
02262       int32_t x, def = result ? *result : 0,
02263          high = (int32_t)0x7fffffff,
02264          low  = (int32_t)0x80000000;
02265       /* optional argument: first default value, then range */
02266       if (flags & PARSE_DEFAULT)
02267          def = va_arg(ap, int32_t);
02268       if (flags & (PARSE_IN_RANGE|PARSE_OUT_RANGE)) {
02269          /* range requested, update bounds */
02270          low = va_arg(ap, int32_t);
02271          high = va_arg(ap, int32_t);
02272       }
02273       x = strtol(arg, NULL, 0);
02274       error = (x < low) || (x > high);
02275       if (flags & PARSE_OUT_RANGE)
02276          error = !error;
02277       if (result)
02278          *result  = error ? def : x;
02279       ast_debug(3,
02280          "extract int from [%s] in [%d, %d] gives [%d](%d)\n",
02281          arg, low, high,
02282          result ? *result : x, error);
02283       break;
02284        }
02285 
02286    case PARSE_UINT32:
02287        {
02288       uint32_t *result = p_result;
02289       uint32_t x, def = result ? *result : 0,
02290          low = 0, high = (uint32_t)~0;
02291       /* optional argument: first default value, then range */
02292       if (flags & PARSE_DEFAULT)
02293          def = va_arg(ap, uint32_t);
02294       if (flags & (PARSE_IN_RANGE|PARSE_OUT_RANGE)) {
02295          /* range requested, update bounds */
02296          low = va_arg(ap, uint32_t);
02297          high = va_arg(ap, uint32_t);
02298       }
02299       x = strtoul(arg, NULL, 0);
02300       error = (x < low) || (x > high);
02301       if (flags & PARSE_OUT_RANGE)
02302          error = !error;
02303       if (result)
02304          *result  = error ? def : x;
02305       ast_debug(3,
02306          "extract uint from [%s] in [%u, %u] gives [%u](%d)\n",
02307          arg, low, high,
02308          result ? *result : x, error);
02309       break;
02310        }
02311 
02312    case PARSE_DOUBLE:
02313        {
02314       double *result = p_result;
02315       double x, def = result ? *result : 0,
02316          low = -HUGE_VAL, high = HUGE_VAL;
02317 
02318       /* optional argument: first default value, then range */
02319       if (flags & PARSE_DEFAULT)
02320          def = va_arg(ap, double);
02321       if (flags & (PARSE_IN_RANGE|PARSE_OUT_RANGE)) {
02322          /* range requested, update bounds */
02323          low = va_arg(ap, double);
02324          high = va_arg(ap, double);
02325       }
02326       x = strtod(arg, NULL);
02327       error = (x < low) || (x > high);
02328       if (flags & PARSE_OUT_RANGE)
02329          error = !error;
02330       if (result)
02331          *result  = error ? def : x;
02332       ast_debug(3,
02333          "extract double from [%s] in [%f, %f] gives [%f](%d)\n",
02334          arg, low, high,
02335          result ? *result : x, error);
02336       break;
02337        }
02338    case PARSE_INADDR:
02339        {
02340       char *port, *buf;
02341       struct sockaddr_in _sa_buf;   /* buffer for the result */
02342       struct sockaddr_in *sa = p_result ?
02343          (struct sockaddr_in *)p_result : &_sa_buf;
02344       /* default is either the supplied value or the result itself */
02345       struct sockaddr_in *def = (flags & PARSE_DEFAULT) ?
02346          va_arg(ap, struct sockaddr_in *) : sa;
02347       struct hostent *hp;
02348       struct ast_hostent ahp;
02349 
02350       memset(&_sa_buf, '\0', sizeof(_sa_buf)); /* clear buffer */
02351       /* duplicate the string to strip away the :port */
02352       port = ast_strdupa(arg);
02353       buf = strsep(&port, ":");
02354       sa->sin_family = AF_INET;  /* assign family */
02355       /*
02356        * honor the ports flag setting, assign default value
02357        * in case of errors or field unset.
02358        */
02359       flags &= PARSE_PORT_MASK; /* the only flags left to process */
02360       if (port) {
02361          if (flags == PARSE_PORT_FORBID) {
02362             error = 1;  /* port was forbidden */
02363             sa->sin_port = def->sin_port;
02364          } else if (flags == PARSE_PORT_IGNORE)
02365             sa->sin_port = def->sin_port;
02366          else /* accept or require */
02367             sa->sin_port = htons(strtol(port, NULL, 0));
02368       } else {
02369          sa->sin_port = def->sin_port;
02370          if (flags == PARSE_PORT_REQUIRE)
02371             error = 1;
02372       }
02373       /* Now deal with host part, even if we have errors before. */
02374       hp = ast_gethostbyname(buf, &ahp);
02375       if (hp)  /* resolved successfully */
02376          memcpy(&sa->sin_addr, hp->h_addr, sizeof(sa->sin_addr));
02377       else {
02378          error = 1;
02379          sa->sin_addr = def->sin_addr;
02380       }
02381       ast_debug(3,
02382          "extract inaddr from [%s] gives [%s:%d](%d)\n",
02383          arg, ast_inet_ntoa(sa->sin_addr),
02384          ntohs(sa->sin_port), error);
02385          break;
02386        }
02387    }
02388    va_end(ap);
02389    return error;
02390 }

int ast_realtime_enabled ( void   ) 

Check if there's any realtime engines loaded.

Definition at line 2143 of file config.c.

References config_maps.

Referenced by action_coresettings(), and handle_show_settings().

02144 {
02145    return config_maps ? 1 : 0;
02146 }

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

Inform realtime what fields that may be stored.

Parameters:
family which 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:
0 Required fields met specified standards
-1 One or more fields was missing or insufficient

Note that you should use the constant SENTINEL to terminate arguments, in order to preserve cross-platform compatibility.

Since:
1.6.1

Definition at line 2148 of file config.c.

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

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

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

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

02215 {
02216    struct ast_config_engine *eng;
02217    int res = -1;
02218    char db[256]="";
02219    char table[256]="";
02220    va_list ap;
02221 
02222    va_start(ap, family);
02223    eng = find_engine(family, db, sizeof(db), table, sizeof(table));
02224    if (eng && eng->store_func) 
02225       res = eng->store_func(db, table, ap);
02226    va_end(ap);
02227 
02228    return res;
02229 }

int ast_unload_realtime ( const char *  family  ) 

Release any resources cached for a realtime family.

Parameters:
family which 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:
0 If any cache was purged
-1 If no cache was found
Since:
1.6.1

Definition at line 2166 of file config.c.

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

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

02167 {
02168    struct ast_config_engine *eng;
02169    char db[256] = "";
02170    char table[256] = "";
02171    int res = -1;
02172 
02173    eng = find_engine(family, db, sizeof(db), table, sizeof(table));
02174    if (eng && eng->unload_func) {
02175       res = eng->unload_func(db, table);
02176    }
02177    return res;
02178 }

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

02198 {
02199    struct ast_config_engine *eng;
02200    int res = -1;
02201    char db[256]="";
02202    char table[256]="";
02203    va_list ap;
02204 
02205    va_start(ap, lookup);
02206    eng = find_engine(family, db, sizeof(db), table, sizeof(table));
02207    if (eng && eng->update_func) 
02208       res = eng->update_func(db, table, keyfield, lookup, ap);
02209    va_end(ap);
02210 
02211    return res;
02212 }

void ast_variable_append ( struct ast_category category,
struct ast_variable variable 
)

Definition at line 343 of file config.c.

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

00344 {
00345    if (!variable)
00346       return;
00347    if (category->last)
00348       category->last->next = variable;
00349    else
00350       category->root = variable;
00351    category->last = variable;
00352    while (category->last->next)
00353       category->last = category->last->next;
00354 }

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

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

Referenced by __ast_http_load(), __ast_http_post_load(), __init_manager(), action_getconfig(), action_getconfigjson(), adsi_load(), aji_load_config(), ast_readconfig(), ast_variable_retrieve(), build_device(), check_tx_freq(), collect_function_digits(), conf_exec(), config_module(), do_say(), do_scheduler(), 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(), node_lookup(), odbc_load_module(), osp_create_provider(), parse_config(), pbx_load_config(), 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_cli_notify(), sla_build_station(), sla_build_trunk(), smdi_load(), store_config(), and tds_load_module().

00390 {
00391    struct ast_category *cat = NULL;
00392 
00393    if (category && config->last_browse && (config->last_browse->name == category))
00394       cat = config->last_browse;
00395    else
00396       cat = ast_category_get(config, category);
00397 
00398    return (cat) ? cat->root : NULL;
00399 }

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

Definition at line 673 of file config.c.

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

Referenced by handle_updates().

00674 {
00675    struct ast_variable *cur, *prev=NULL, *curn;
00676    int res = -1;
00677    int lineno = 0;
00678 
00679    cur = category->root;
00680    while (cur) {
00681       if (cur->name == variable) {
00682          if (prev) {
00683             prev->next = cur->next;
00684             if (cur == category->last)
00685                category->last = prev;
00686          } else {
00687             category->root = cur->next;
00688             if (cur == category->last)
00689                category->last = NULL;
00690          }
00691          cur->next = NULL;
00692          ast_variables_destroy(cur);
00693          return 0;
00694       }
00695       prev = cur;
00696       cur = cur->next;
00697    }
00698 
00699    prev = NULL;
00700    cur = category->root;
00701    while (cur) {
00702       curn = cur->next;
00703       if ((!ast_strlen_zero(line) && lineno == atoi(line)) || (ast_strlen_zero(line) && !strcasecmp(cur->name, variable) && (ast_strlen_zero(match) || !strcasecmp(cur->value, match)))) {
00704          if (prev) {
00705             prev->next = cur->next;
00706             if (cur == category->last)
00707                category->last = prev;
00708          } else {
00709             category->root = cur->next;
00710             if (cur == category->last)
00711                category->last = NULL;
00712          }
00713          cur->next = NULL;
00714          ast_variables_destroy(cur);
00715          res = 0;
00716       } else
00717          prev = cur;
00718 
00719       cur = curn;
00720       lineno++;
00721    }
00722    return res;
00723 }

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

Definition at line 356 of file config.c.

References ast_variable::next.

Referenced by handle_updates().

00357 {
00358    struct ast_variable *cur = category->root;
00359    int lineno;
00360    int insertline;
00361 
00362    if (!variable || sscanf(line, "%30d", &insertline) != 1)
00363       return;
00364    if (!insertline) {
00365       variable->next = category->root;
00366       category->root = variable;
00367    } else {
00368       for (lineno = 1; lineno < insertline; lineno++) {
00369          cur = cur->next;
00370          if (!cur->next)
00371             break;
00372       }
00373       variable->next = cur->next;
00374       cur->next = variable;
00375    }
00376 }

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

Definition at line 218 of file config.c.

References __ast_calloc(), 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(), 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(), transmit_notify_custom(), variable_clone(), and vm_change_password().

00220 {
00221    struct ast_variable *variable;
00222    int name_len = strlen(name) + 1; 
00223    int val_len = strlen(value) + 1; 
00224    int fn_len = strlen(filename) + 1;  
00225 
00226 #ifdef MALLOC_DEBUG
00227    if ((variable = __ast_calloc(1, name_len + val_len + fn_len + sizeof(*variable), file, lineno, func))) {
00228 #else
00229    if ((variable = ast_calloc(1, name_len + val_len + fn_len + sizeof(*variable)))) {
00230 #endif
00231       char *dst = variable->stuff;  /* writable space starts here */
00232       variable->name = strcpy(dst, name);
00233       dst += name_len;
00234       variable->value = strcpy(dst, value);
00235       dst += val_len;
00236       variable->file = strcpy(dst, filename);
00237    }
00238    return variable;
00239 }

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

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

Referenced by __ast_rtp_reload(), __ast_udptl_reload(), __init_manager(), _dsp_init(), advanced_options(), aji_load_config(), ast_config_option(), build_extension(), config_function_read(), config_module(), directory_exec(), do_reload(), do_scheduler(), festival_exec(), find_queue_by_name_rt(), function_macro(), 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(), load_rpt_vars(), make_email_file(), node_lookup(), 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(), realtime_directory(), reload_config(), reload_followme(), reload_queues(), retreive_memory(), retrieve_astcfgint(), rpt(), rpt_master(), rpt_tele_thread(), rpt_telemetry(), saynode(), 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().

00412 {
00413    struct ast_variable *v;
00414 
00415    if (category) {
00416       for (v = ast_variable_browse(config, category); v; v = v->next) {
00417          if (!strcasecmp(variable, v->name))
00418             return v->value;
00419       }
00420    } else {
00421       struct ast_category *cat;
00422 
00423       for (cat = config->root; cat; cat = cat->next)
00424          for (v = cat->root; v; v = v->next)
00425             if (!strcasecmp(variable, v->name))
00426                return v->value;
00427    }
00428 
00429    return NULL;
00430 }

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:
category Category element within the config
variable Name of the variable to change
value New value of the variable
match If set, previous value of the variable (if NULL or zero-length, no matching will be done)
object Boolean of whether to make the new variable an object
Returns:
0 on success or -1 on failure.

Definition at line 725 of file config.c.

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

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

00727 {
00728    struct ast_variable *cur, *prev=NULL, *newer=NULL;
00729 
00730    for (cur = category->root; cur; prev = cur, cur = cur->next) {
00731       if (strcasecmp(cur->name, variable) ||
00732          (!ast_strlen_zero(match) && strcasecmp(cur->value, match)))
00733          continue;
00734 
00735       if (!(newer = ast_variable_new(variable, value, cur->file)))
00736          return -1;
00737    
00738       newer->next = cur->next;
00739       newer->object = cur->object || object;
00740 
00741       /* Preserve everything */
00742       newer->lineno = cur->lineno;
00743       newer->blanklines = cur->blanklines;
00744       newer->precomments = cur->precomments; cur->precomments = NULL;
00745       newer->sameline = cur->sameline; cur->sameline = NULL;
00746       newer->trailing = cur->trailing; cur->trailing = NULL;
00747 
00748       if (prev)
00749          prev->next = newer;
00750       else
00751          category->root = newer;
00752       if (category->last == cur)
00753          category->last = newer;
00754 
00755       cur->next = NULL;
00756       ast_variables_destroy(cur);
00757 
00758       return 0;
00759    }
00760 
00761    /* Could not find variable to update */
00762    return -1;
00763 }

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 1580 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_variable::next, ast_comment::next, ast_config_include::next, ast_variable::object, option_debug, ast_config_include::output, ast_variable::precomments, ast_config::root, ast_variable::sameline, set_fn(), ast_variable::trailing, ast_variable::value, and var.

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

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

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

01869 {
01870    struct ast_config *config, *configtmp;
01871    struct ast_variable *v;
01872    char *driver, *table, *database, *stringp, *tmp;
01873    struct ast_flags flags = { 0 };
01874 
01875    clear_config_maps();
01876 
01877    configtmp = ast_config_new();
01878    configtmp->max_include_level = 1;
01879    config = ast_config_internal_load(extconfig_conf, configtmp, flags, "", "extconfig");
01880    if (!config) {
01881       ast_config_destroy(configtmp);
01882       return 0;
01883    }
01884 
01885    for (v = ast_variable_browse(config, "settings"); v; v = v->next) {
01886       char buf[512];
01887       ast_copy_string(buf, v->value, sizeof(buf));
01888       stringp = buf;
01889       driver = strsep(&stringp, ",");
01890 
01891       if ((tmp = strchr(stringp, '\"')))
01892          stringp = tmp;
01893 
01894       /* check if the database text starts with a double quote */
01895       if (*stringp == '"') {
01896          stringp++;
01897          database = strsep(&stringp, "\"");
01898          strsep(&stringp, ",");
01899       } else {
01900          /* apparently this text has no quotes */
01901          database = strsep(&stringp, ",");
01902       }
01903 
01904       table = strsep(&stringp, ",");
01905 
01906       if (!strcmp(v->name, extconfig_conf)) {
01907          ast_log(LOG_WARNING, "Cannot bind '%s'!\n", extconfig_conf);
01908          continue;
01909       }
01910 
01911       if (!strcmp(v->name, "asterisk.conf")) {
01912          ast_log(LOG_WARNING, "Cannot bind 'asterisk.conf'!\n");
01913          continue;
01914       }
01915 
01916       if (!strcmp(v->name, "logger.conf")) {
01917          ast_log(LOG_WARNING, "Cannot bind 'logger.conf'!\n");
01918          continue;
01919       }
01920 
01921       if (!driver || !database)
01922          continue;
01923       if (!strcasecmp(v->name, "sipfriends")) {
01924          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");
01925          append_mapping("sipusers", driver, database, table ? table : "sipfriends");
01926          append_mapping("sippeers", driver, database, table ? table : "sipfriends");
01927       } else if (!strcasecmp(v->name, "iaxfriends")) {
01928          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");
01929          append_mapping("iaxusers", driver, database, table ? table : "iaxfriends");
01930          append_mapping("iaxpeers", driver, database, table ? table : "iaxfriends");
01931       } else 
01932          append_mapping(v->name, driver, database, table);
01933    }
01934       
01935    ast_config_destroy(config);
01936    return 0;
01937 }

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

References ast_cli_register_multiple().

Referenced by main().

02524 {
02525    ast_cli_register_multiple(cli_config, sizeof(cli_config) / sizeof(struct ast_cli_entry));
02526    return 0;
02527 }


Generated on 3 Mar 2010 for Asterisk - the Open Source PBX by  doxygen 1.6.1