Fri May 26 01:48:16 2006

Asterisk developer's documentation


config.h File Reference

Configuration File Parser. More...

#include <stdarg.h>

Include dependency graph for config.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_config_engine
struct  ast_variable

Typedefs

typedef ast_configconfig_load_func (const char *database, const char *table, const char *configfile, struct ast_config *config)
typedef ast_configrealtime_multi_get (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 ast_variablerealtime_var_get (const char *database, const char *table, va_list ap)

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, char *category)
void ast_category_destroy (struct ast_category *cat)
ast_variableast_category_detach_variables (struct ast_category *cat)
int ast_category_exist (const struct ast_config *config, const char *category_name)
 Check for category duplicates.
ast_categoryast_category_get (const struct ast_config *config, const char *category_name)
 Retrieve a category if it exists.
ast_categoryast_category_new (const char *name)
void ast_category_rename (struct ast_category *cat, const char *name)
int ast_check_realtime (const char *family)
 Check if realtime engine is configured for family returns 1 if family is configured in realtime and engine exists.
void ast_config_destroy (struct ast_config *config)
 Destroys a config.
int ast_config_engine_deregister (struct ast_config_engine *del)
 Deegister config engine.
int ast_config_engine_register (struct ast_config_engine *newconfig)
 Register config engine.
ast_categoryast_config_get_current_category (const struct ast_config *cfg)
ast_configast_config_internal_load (const char *configfile, struct ast_config *cfg)
ast_configast_config_load (const char *filename)
 Load a config file.
ast_configast_config_new (void)
void ast_config_set_current_category (struct ast_config *cfg, const struct ast_category *cat)
ast_variableast_load_realtime (const char *family,...)
 Retrieve realtime configuration.
ast_configast_load_realtime_multientry (const char *family,...)
 Retrieve 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)
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_config *cfg, char *category, char *variable, char *value)
ast_variableast_variable_new (const char *name, const char *value)
char * ast_variable_retrieve (const struct ast_config *config, const char *category, const char *variable)
 Gets a variable.
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)
void read_config_maps (void)
int register_config_cli (void)


Detailed Description

Configuration File Parser.

Definition in file config.h.


Typedef Documentation

typedef struct ast_config* config_load_func(const char *database, const char *table, const char *configfile, struct ast_config *config)
 

Definition at line 48 of file config.h.

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

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

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

Definition at line 49 of file config.h.


Function Documentation

void ast_category_append struct ast_config config,
struct ast_category cat
 

Definition at line 240 of file config.c.

References config.

Referenced by config_odbc(), process_text_line(), realtime_directory(), and realtime_multi_odbc().

00241 {
00242    if (config->last)
00243       config->last->next = category;
00244    else
00245       config->root = category;
00246    config->last = category;
00247    config->current = category;
00248 }

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 funtion is kind of non-intuitive in it's use. To begin, one passes NULL as the second arguement. 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.
Returns a category on success, or NULL on failure/no-more-categories

Definition at line 263 of file config.c.

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

Referenced by authenticate(), complete_sipnotify(), config_load(), iax_provision_reload(), ind_load_module(), load_module(), load_moh_classes(), load_odbc_config(), loadconfigurationfile(), misdn_cfg_init(), pbx_load_module(), realtime_directory(), realtime_switch_common(), reload_config(), reload_queues(), rpt_master(), and set_config().

00264 {  
00265    struct ast_category *cat = NULL;
00266 
00267    if (prev && config->last_browse && (config->last_browse->name == prev))
00268       cat = config->last_browse->next;
00269    else if (!prev && config->root)
00270          cat = config->root;
00271    else if (prev) {
00272       for (cat = config->root; cat; cat = cat->next) {
00273          if (cat->name == prev) {
00274             cat = cat->next;
00275             break;
00276          }
00277       }
00278       if (!cat) {
00279          for (cat = config->root; cat; cat = cat->next) {
00280             if (!strcasecmp(cat->name, prev)) {
00281                cat = cat->next;
00282                break;
00283             }
00284          }
00285       }
00286    }
00287    
00288    if (cat)
00289       cat = next_available_category(cat);
00290 
00291    config->last_browse = cat;
00292    if (cat)
00293       return cat->name;
00294    else
00295       return NULL;
00296 }

int ast_category_delete struct ast_config cfg,
char *  category
 

void ast_category_destroy struct ast_category cat  ) 
 

Definition at line 250 of file config.c.

References ast_variables_destroy(), free, and ast_category::root.

Referenced by process_text_line(), and realtime_multi_odbc().

00251 {
00252    ast_variables_destroy(cat->root);
00253    free(cat);
00254 }

struct ast_variable* ast_category_detach_variables struct ast_category cat  ) 
 

Definition at line 298 of file config.c.

References ast_category::root.

Referenced by realtime_switch_common().

00299 {
00300    struct ast_variable *v;
00301 
00302    v = cat->root;
00303    cat->root = NULL;
00304 
00305    return v;
00306 }

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.
Return non-zero if found

Definition at line 235 of file config.c.

References ast_category_get(), and config.

00236 {
00237    return !!ast_category_get(config, category_name);
00238 }

struct ast_category* ast_category_get const struct ast_config config,
const char *  category_name
 

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.
Returns pointer to category if found, NULL if not.

Definition at line 230 of file config.c.

References category_get(), and config.

Referenced by ast_category_exist(), ast_variable_browse(), realtime_directory(), and realtime_switch_common().

00231 {
00232    return category_get(config, category_name, 0);
00233 }

struct ast_category* ast_category_new const char *  name  ) 
 

Definition at line 200 of file config.c.

References malloc.

Referenced by config_odbc(), process_text_line(), realtime_directory(), and realtime_multi_odbc().

00201 {
00202    struct ast_category *category;
00203 
00204    category = malloc(sizeof(struct ast_category));
00205    if (category) {
00206       memset(category, 0, sizeof(struct ast_category));
00207       ast_copy_string(category->name, name, sizeof(category->name));
00208    }
00209 
00210    return category;
00211 }

void ast_category_rename struct ast_category cat,
const char *  name
 

Definition at line 308 of file config.c.

References ast_category::name.

Referenced by realtime_multi_odbc().

00309 {
00310    ast_copy_string(cat->name, name, sizeof(cat->name));
00311 }

int ast_check_realtime const char *  family  ) 
 

Check if realtime engine is configured for family returns 1 if family is configured in realtime and engine exists.

Parameters:
family which family/config to be checked

Definition at line 1001 of file config.c.

References find_engine().

Referenced by sip_show_settings().

01002 {
01003    struct ast_config_engine *eng;
01004 
01005    eng = find_engine(family, NULL, 0, NULL, 0);
01006    if (eng)
01007       return 1;
01008    return 0;
01009 
01010 }

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

References ast_variables_destroy(), cfg, free, ast_category::next, ast_category::root, and ast_config::root.

Referenced by adsi_load(), advanced_options(), ast_config_load(), ast_enum_init(), ast_load_resource(), ast_readconfig(), ast_rtp_reload(), authenticate(), conf_exec(), config_load(), do_reload(), festival_exec(), forward_message(), handle_save_dialplan(), iax_provision_reload(), ind_load_module(), init_logger_chain(), init_manager(), load_config(), load_module(), load_modules(), loadconfigurationfile(), my_load_module(), odbc_load_module(), parse_config(), pbx_load_module(), play_message(), privacy_exec(), process_text_line(), read_agent_config(), read_config_maps(), realtime_directory(), realtime_switch_common(), reload_config(), reload_queues(), set_config(), setup_zap(), and tds_load_module().

00340 {
00341    struct ast_category *cat, *catn;
00342 
00343    if (!cfg)
00344       return;
00345 
00346    cat = cfg->root;
00347    while(cat) {
00348       ast_variables_destroy(cat->root);
00349       catn = cat;
00350       cat = cat->next;
00351       free(catn);
00352    }
00353    free(cfg);
00354 }

int ast_config_engine_deregister struct ast_config_engine del  ) 
 

Deegister config engine.

Definition at line 868 of file config.c.

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

Referenced by unload_module().

00869 {
00870    struct ast_config_engine *ptr, *last=NULL;
00871 
00872    ast_mutex_lock(&config_lock);
00873 
00874    for (ptr = config_engine_list; ptr; ptr=ptr->next) {
00875       if (ptr == del) {
00876          if (last)
00877             last->next = ptr->next;
00878          else
00879             config_engine_list = ptr->next;
00880          break;
00881       }
00882       last = ptr;
00883    }
00884 
00885    ast_mutex_unlock(&config_lock);
00886 
00887    return 0;
00888 }

int ast_config_engine_register struct ast_config_engine newconfig  ) 
 

Register config engine.

Definition at line 849 of file config.c.

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

Referenced by load_module().

00850 {
00851    struct ast_config_engine *ptr;
00852 
00853    ast_mutex_lock(&config_lock);
00854 
00855    if (!config_engine_list) {
00856       config_engine_list = new;
00857    } else {
00858       for (ptr = config_engine_list; ptr->next; ptr=ptr->next);
00859       ptr->next = new;
00860    }
00861 
00862    ast_mutex_unlock(&config_lock);
00863    ast_log(LOG_NOTICE,"Registered Config Engine %s\n", new->name);
00864 
00865    return 1;
00866 }

struct ast_category* ast_config_get_current_category const struct ast_config cfg  ) 
 

Definition at line 356 of file config.c.

References cfg, and ast_config::current.

Referenced by config_odbc(), and config_text_file_load().

00357 {
00358    return cfg->current;
00359 }

struct ast_config* ast_config_internal_load const char *  configfile,
struct ast_config cfg
 

Definition at line 930 of file config.c.

References ast_log(), cfg, config_engine_list, db, extconfig_conf, find_engine(), ast_config::include_level, ast_config_engine::load_func, LOG_WARNING, ast_config::max_include_level, result, table, and text_file_engine.

Referenced by ast_config_load(), config_odbc(), process_text_line(), and read_config_maps().

00931 {
00932    char db[256];
00933    char table[256];
00934    struct ast_config_engine *loader = &text_file_engine;
00935    struct ast_config *result;
00936 
00937    if (cfg->include_level == cfg->max_include_level) {
00938       ast_log(LOG_WARNING, "Maximum Include level (%d) exceeded\n", cfg->max_include_level);
00939       return NULL;
00940    }
00941 
00942    cfg->include_level++;
00943 
00944    if (strcmp(filename, extconfig_conf) && strcmp(filename, "asterisk.conf") && config_engine_list) {
00945       struct ast_config_engine *eng;
00946 
00947       eng = find_engine(filename, db, sizeof(db), table, sizeof(table));
00948 
00949 
00950       if (eng && eng->load_func) {
00951          loader = eng;
00952       } else {
00953          eng = find_engine("global", db, sizeof(db), table, sizeof(table));
00954          if (eng && eng->load_func)
00955             loader = eng;
00956       }
00957    }
00958 
00959    result = loader->load_func(db, table, filename, cfg);
00960 
00961    if (result)
00962       result->include_level--;
00963 
00964    return result;
00965 }

struct ast_config* ast_config_load const char *  filename  ) 
 

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.
Returns NULL on error, or an ast_config data structure on success

Definition at line 967 of file config.c.

References ast_config_destroy(), ast_config_internal_load(), ast_config_new(), cfg, and result.

Referenced by adsi_load(), advanced_options(), ast_enum_init(), ast_load_resource(), ast_readconfig(), ast_rtp_reload(), authenticate(), conf_exec(), config_load(), do_reload(), festival_exec(), forward_message(), handle_save_dialplan(), iax_provision_reload(), ind_load_module(), init_logger_chain(), init_manager(), load_config(), load_module(), load_modules(), load_moh_classes(), load_odbc_config(), loadconfigurationfile(), my_load_module(), odbc_load_module(), parse_config(), pbx_load_module(), play_message(), privacy_exec(), read_agent_config(), realtime_directory(), reload_config(), reload_queues(), rpt_master(), set_config(), setup_zap(), and tds_load_module().

00968 {
00969    struct ast_config *cfg;
00970    struct ast_config *result;
00971 
00972    cfg = ast_config_new();
00973    if (!cfg)
00974       return NULL;
00975 
00976    result = ast_config_internal_load(filename, cfg);
00977    if (!result)
00978       ast_config_destroy(cfg);
00979 
00980    return result;
00981 }

struct ast_config* ast_config_new void   ) 
 

Definition at line 326 of file config.c.

References config, malloc, and MAX_INCLUDE_LEVEL.

Referenced by ast_config_load(), read_config_maps(), and realtime_multi_odbc().

00327 {
00328    struct ast_config *config;
00329 
00330    config = malloc(sizeof(*config));
00331    if (config) {
00332       memset(config, 0, sizeof(*config));
00333       config->max_include_level = MAX_INCLUDE_LEVEL;
00334    }
00335 
00336    return config;
00337 }

void ast_config_set_current_category struct ast_config cfg,
const struct ast_category cat
 

Definition at line 361 of file config.c.

References cfg, and ast_config::current.

00362 {
00363    /* cast below is just to silence compiler warning about dropping "const" */
00364    cfg->current = (struct ast_category *) cat;
00365 }

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

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 fred with ast_free_runtime() as there is no container.

Definition at line 983 of file config.c.

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

Referenced by cli_load_realtime(), find_user_realtime(), realtime_exec(), realtime_peer(), realtime_switch_common(), and realtime_user().

00984 {
00985    struct ast_config_engine *eng;
00986    char db[256]="";
00987    char table[256]="";
00988    struct ast_variable *res=NULL;
00989    va_list ap;
00990 
00991    va_start(ap, family);
00992    eng = find_engine(family, db, sizeof(db), table, sizeof(table));
00993    if (eng && eng->realtime_func) 
00994       res = eng->realtime_func(db, table, ap);
00995    va_end(ap);
00996 
00997    return res;
00998 }

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

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

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

Referenced by realtime_directory(), and realtime_switch_common().

01013 {
01014    struct ast_config_engine *eng;
01015    char db[256]="";
01016    char table[256]="";
01017    struct ast_config *res=NULL;
01018    va_list ap;
01019 
01020    va_start(ap, family);
01021    eng = find_engine(family, db, sizeof(db), table, sizeof(table));
01022    if (eng && eng->realtime_multi_func) 
01023       res = eng->realtime_multi_func(db, table, ap);
01024    va_end(ap);
01025 
01026    return res;
01027 }

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.

Definition at line 1029 of file config.c.

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

Referenced by change_password_realtime(), cli_update_realtime(), destroy_association(), realtime_update_exec(), and realtime_update_peer().

01030 {
01031    struct ast_config_engine *eng;
01032    int res = -1;
01033    char db[256]="";
01034    char table[256]="";
01035    va_list ap;
01036 
01037    va_start(ap, lookup);
01038    eng = find_engine(family, db, sizeof(db), table, sizeof(table));
01039    if (eng && eng->update_func) 
01040       res = eng->update_func(db, table, keyfield, lookup, ap);
01041    va_end(ap);
01042 
01043    return res;
01044 }

void ast_variable_append struct ast_category category,
struct ast_variable variable
 

Definition at line 116 of file config.c.

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

Referenced by config_odbc(), inherit_category(), move_variables(), process_text_line(), realtime_directory(), and realtime_multi_odbc().

00117 {
00118    if (category->last)
00119       category->last->next = variable;
00120    else
00121       category->root = variable;
00122    category->last = variable;
00123 }

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

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

Returns ast_variable list on success, or NULL on failure

Definition at line 136 of file config.c.

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

Referenced by adsi_load(), ast_enum_init(), ast_readconfig(), ast_variable_retrieve(), authenticate(), collect_function_digits(), conf_exec(), do_directory(), handle_save_dialplan(), iax_template_parse(), ind_load_module(), init_logger_chain(), load_config(), load_module(), load_modules(), load_moh_classes(), load_odbc_config(), loadconfigurationfile(), misdn_cfg_init(), odbc_load_module(), osp_build(), parse_config(), pbx_load_module(), process_my_load_module(), read_agent_config(), read_config_maps(), reload_config(), reload_queues(), set_config(), setup_zap(), sip_notify(), store_config(), and tds_load_module().

00137 {
00138    struct ast_category *cat = NULL;
00139 
00140    if (category && config->last_browse && (config->last_browse->name == category))
00141       cat = config->last_browse;
00142    else
00143       cat = ast_category_get(config, category);
00144 
00145    if (cat)
00146       return cat->root;
00147    else
00148       return NULL;
00149 }

int ast_variable_delete struct ast_config cfg,
char *  category,
char *  variable,
char *  value
 

struct ast_variable* ast_variable_new const char *  name,
const char *  value
 

Definition at line 99 of file config.c.

References malloc.

Referenced by apply_outgoing(), astman_get_variables(), build_peer(), build_user(), check_access(), check_user_full(), config_odbc(), launch_page(), process_text_line(), realtime_directory(), realtime_multi_odbc(), realtime_odbc(), and variable_clone().

00100 {
00101    struct ast_variable *variable;
00102 
00103    int length = strlen(name) + strlen(value) + 2 + sizeof(struct ast_variable);
00104    variable = malloc(length);
00105    if (variable) {
00106       memset(variable, 0, length);
00107       variable->name = variable->stuff;
00108       variable->value = variable->stuff + strlen(name) + 1;    
00109       strcpy(variable->name,name);
00110       strcpy(variable->value,value);
00111    }
00112 
00113    return variable;
00114 }

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
Returns the variable value on success, or NULL if unable to find it.

Definition at line 151 of file config.c.

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

Referenced by __load_resource(), advanced_options(), ast_rtp_reload(), attempt_reconnect(), authenticate(), config_load(), directory_exec(), do_reload(), festival_exec(), forward_message(), function_ilink(), function_remote(), get_wait_interval(), iax_template_parse(), ind_load_module(), init_logger_chain(), init_manager(), load_config(), odbc_load_module(), pbx_load_module(), play_message(), privacy_exec(), process_my_load_module(), read_agent_config(), realtime_directory(), reload_config(), reload_queues(), retrieve_astcfgint(), rpt(), rpt_master(), set_config(), tds_load_module(), and telem_lookup().

00152 {
00153    struct ast_variable *v;
00154 
00155    if (category) {
00156       for (v = ast_variable_browse(config, category); v; v = v->next) {
00157          if (!strcasecmp(variable, v->name))
00158             return v->value;
00159       }
00160    } else {
00161       struct ast_category *cat;
00162 
00163       for (cat = config->root; cat; cat = cat->next)
00164          for (v = cat->root; v; v = v->next)
00165             if (!strcasecmp(variable, v->name))
00166                return v->value;
00167    }
00168 
00169    return NULL;
00170 }

void ast_variables_destroy struct ast_variable var  ) 
 

Free variable list.

Parameters:
var the linked list of variables to free This function frees a list of variables.

Definition at line 125 of file config.c.

References free, and ast_variable::next.

Referenced by __sip_destroy(), ast_category_destroy(), ast_config_destroy(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), build_peer(), destroy_user(), iax2_destroy(), realtime_canmatch(), realtime_exec(), realtime_exists(), realtime_matchmore(), realtime_odbc(), realtime_peer(), realtime_user(), sip_alloc(), sip_destroy_peer(), sip_destroy_user(), and unload_module().

00126 {
00127    struct ast_variable *vn;
00128 
00129    while(v) {
00130       vn = v;
00131       v = v->next;
00132       free(vn);
00133    }
00134 }

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

Definition at line 678 of file config.c.

References ast_config_AST_CONFIG_DIR, ast_verbose(), cfg, ast_category::name, ast_category::next, option_debug, option_verbose, ast_category::root, ast_config::root, t, var, and VERBOSE_PREFIX_2.

00679 {
00680    FILE *f;
00681    char fn[256];
00682    char date[256]="";
00683    time_t t;
00684    struct ast_variable *var;
00685    struct ast_category *cat;
00686    int blanklines = 0;
00687 
00688    if (configfile[0] == '/') {
00689       ast_copy_string(fn, configfile, sizeof(fn));
00690    } else {
00691       snprintf(fn, sizeof(fn), "%s/%s", ast_config_AST_CONFIG_DIR, configfile);
00692    }
00693    time(&t);
00694    ast_copy_string(date, ctime(&t), sizeof(date));
00695 #ifdef __CYGWIN__ 
00696    if ((f = fopen(fn, "w+"))) {
00697 #else
00698    if ((f = fopen(fn, "w"))) {
00699 #endif       
00700       if ((option_verbose > 1) && !option_debug)
00701          ast_verbose(  VERBOSE_PREFIX_2 "Saving '%s': ", fn);
00702       fprintf(f, ";!\n");
00703       fprintf(f, ";! Automatically generated configuration file\n");
00704       fprintf(f, ";! Filename: %s (%s)\n", configfile, fn);
00705       fprintf(f, ";! Generator: %s\n", generator);
00706       fprintf(f, ";! Creation Date: %s", date);
00707       fprintf(f, ";!\n");
00708       cat = cfg->root;
00709       while(cat) {
00710          /* Dump section with any appropriate comment */
00711          fprintf(f, "[%s]\n", cat->name);
00712          var = cat->root;
00713          while(var) {
00714             if (var->sameline) 
00715                fprintf(f, "%s %s %s  ; %s\n", var->name, (var->object ? "=>" : "="), var->value, var->sameline->cmt);
00716             else  
00717                fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="), var->value);
00718             if (var->blanklines) {
00719                blanklines = var->blanklines;
00720                while (blanklines--)
00721                   fprintf(f, "\n");
00722             }
00723                
00724             var = var->next;
00725          }
00726 #if 0
00727          /* Put an empty line */
00728          fprintf(f, "\n");
00729 #endif
00730          cat = cat->next;
00731       }
00732    } else {
00733       if (option_debug)
00734          printf("Unable to open for writing: %s\n", fn);
00735       else if (option_verbose > 1)
00736          printf( "Unable to write (%s)", strerror(errno));
00737       return -1;
00738    }
00739    fclose(f);
00740    return 0;
00741 }

void read_config_maps void   ) 
 

Definition at line 795 of file config.c.

References append_mapping(), ast_config_destroy(), ast_config_internal_load(), ast_config_new(), ast_log(), ast_variable_browse(), 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 ast_module_reload().

00796 {
00797    struct ast_config *config, *configtmp;
00798    struct ast_variable *v;
00799    char *driver, *table, *database, *stringp;
00800 
00801    clear_config_maps();
00802 
00803    configtmp = ast_config_new();
00804    configtmp->max_include_level = 1;
00805    config = ast_config_internal_load(extconfig_conf, configtmp);
00806    if (!config) {
00807       ast_config_destroy(configtmp);
00808       return;
00809    }
00810 
00811    for (v = ast_variable_browse(config, "settings"); v; v = v->next) {
00812       stringp = v->value;
00813       driver = strsep(&stringp, ",");
00814       database = strsep(&stringp, ",");
00815       table = strsep(&stringp, ",");
00816          
00817       if (!strcmp(v->name, extconfig_conf)) {
00818          ast_log(LOG_WARNING, "Cannot bind '%s'!\n", extconfig_conf);
00819          continue;
00820       }
00821 
00822       if (!strcmp(v->name, "asterisk.conf")) {
00823          ast_log(LOG_WARNING, "Cannot bind 'asterisk.conf'!\n");
00824          continue;
00825       }
00826 
00827       if (!strcmp(v->name, "logger.conf")) {
00828          ast_log(LOG_WARNING, "Cannot bind 'logger.conf'!\n");
00829          continue;
00830       }
00831 
00832       if (!driver || !database)
00833          continue;
00834       if (!strcasecmp(v->name, "sipfriends")) {
00835          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");
00836          append_mapping("sipusers", driver, database, table ? table : "sipfriends");
00837          append_mapping("sippeers", driver, database, table ? table : "sipfriends");
00838       } else if (!strcasecmp(v->name, "iaxfriends")) {
00839          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");
00840          append_mapping("iaxusers", driver, database, table ? table : "iaxfriends");
00841          append_mapping("iaxpeers", driver, database, table ? table : "iaxfriends");
00842       } else 
00843          append_mapping(v->name, driver, database, table);
00844    }
00845       
00846    ast_config_destroy(config);
00847 }

int register_config_cli void   ) 
 

Definition at line 1077 of file config.c.

References ast_cli_register(), and config_command_struct.

01078 {
01079    return ast_cli_register(&config_command_struct);
01080 }


Generated on Fri May 26 01:48:21 2006 for Asterisk - the Open Source PBX by  doxygen 1.4.6