Fri Sep 25 19:28:34 2009

Asterisk developer's documentation


config.h File Reference

Configuration File Parser. More...

#include <stdarg.h>

Include dependency graph for config.h:

Go to the source code of this file.

Data Structures

struct  ast_config_engine
struct  ast_variable

Typedefs

typedef struct ast_configconfig_load_func (const char *database, const char *table, const char *configfile, struct ast_config *config, int withcomments)
typedef struct 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 struct 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)
struct 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.
struct ast_categoryast_category_get (const struct ast_config *config, const char *category_name)
 Retrieve a category if it exists.
struct ast_categoryast_category_new (const char *name)
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 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.
struct ast_categoryast_config_get_current_category (const struct ast_config *cfg)
struct ast_configast_config_internal_load (const char *configfile, struct ast_config *cfg, int withcomments)
struct ast_configast_config_load (const char *filename)
 Load a config file.
struct ast_configast_config_load_with_comments (const char *filename)
struct ast_configast_config_new (void)
const char * ast_config_option (struct ast_config *cfg, const char *cat, const char *var)
void ast_config_set_current_category (struct ast_config *cfg, const struct ast_category *cat)
struct ast_variableast_load_realtime (const char *family,...)
 Retrieve realtime configuration.
struct 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)
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, char *variable, char *match)
struct ast_variableast_variable_new (const char *name, const char *value)
const char * ast_variable_retrieve (const struct ast_config *config, const char *category, const char *variable)
 Gets a variable.
int ast_variable_update (struct ast_category *category, const char *variable, const char *value, const char *match, unsigned int object)
void ast_variables_destroy (struct ast_variable *var)
 Free variable list.
int config_text_file_save (const char *filename, const struct ast_config *cfg, const char *generator)
int read_config_maps (void)
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, int withcomments)

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 339 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 config_odbc(), config_pgsql(), handle_updates(), process_text_line(), realtime_directory(), realtime_multi_odbc(), and realtime_multi_pgsql().

00340 {
00341    if (config->last)
00342       config->last->next = category;
00343    else
00344       config->root = category;
00345    category->include_level = config->include_level;
00346    config->last = category;
00347    config->current = category;
00348 }

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

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

Referenced by action_getconfig(), aji_load_config(), authenticate(), complete_sipnotify(), do_directory(), find_queue_by_name_rt(), gtalk_load_config(), iax_provision_reload(), ind_load_module(), init_manager(), load_config(), load_module(), load_moh_classes(), load_odbc_config(), loadconfigurationfile(), misdn_cfg_init(), odbc_load_module(), osp_load(), pbx_load_config(), pbx_load_users(), read_agent_config(), realtime_directory(), realtime_peer(), realtime_switch_common(), reload(), reload_config(), reload_followme(), reload_queues(), rpt_master(), set_config(), setup_zap(), sla_load_config(), update_realtime_members(), and vm_change_password().

00399 {  
00400    struct ast_category *cat = NULL;
00401 
00402    if (prev && config->last_browse && (config->last_browse->name == prev))
00403       cat = config->last_browse->next;
00404    else if (!prev && config->root)
00405       cat = config->root;
00406    else if (prev) {
00407       for (cat = config->root; cat; cat = cat->next) {
00408          if (cat->name == prev) {
00409             cat = cat->next;
00410             break;
00411          }
00412       }
00413       if (!cat) {
00414          for (cat = config->root; cat; cat = cat->next) {
00415             if (!strcasecmp(cat->name, prev)) {
00416                cat = cat->next;
00417                break;
00418             }
00419          }
00420       }
00421    }
00422    
00423    if (cat)
00424       cat = next_available_category(cat);
00425 
00426    config->last_browse = cat;
00427    return (cat) ? cat->name : NULL;
00428 }

int ast_category_delete ( struct ast_config cfg,
char *  category 
)

Definition at line 553 of file config.c.

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

Referenced by handle_updates().

00554 {
00555    struct ast_category *prev=NULL, *cat;
00556    cat = cfg->root;
00557    while(cat) {
00558       if (cat->name == category) {
00559          if (prev) {
00560             prev->next = cat->next;
00561             if (cat == cfg->last)
00562                cfg->last = prev;
00563          } else {
00564             cfg->root = cat->next;
00565             if (cat == cfg->last)
00566                cfg->last = NULL;
00567          }
00568          ast_category_destroy(cat);
00569          return 0;
00570       }
00571       prev = cat;
00572       cat = cat->next;
00573    }
00574 
00575    prev = NULL;
00576    cat = cfg->root;
00577    while(cat) {
00578       if (!strcasecmp(cat->name, category)) {
00579          if (prev) {
00580             prev->next = cat->next;
00581             if (cat == cfg->last)
00582                cfg->last = prev;
00583          } else {
00584             cfg->root = cat->next;
00585             if (cat == cfg->last)
00586                cfg->last = NULL;
00587          }
00588          ast_category_destroy(cat);
00589          return 0;
00590       }
00591       prev = cat;
00592       cat = cat->next;
00593    }
00594    return -1;
00595 }

void ast_category_destroy ( struct ast_category cat  ) 

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

Definition at line 430 of file config.c.

Referenced by realtime_switch_common().

00431 {
00432    struct ast_variable *v;
00433 
00434    v = cat->root;
00435    cat->root = NULL;
00436    cat->last = NULL;
00437 
00438    return v;
00439 }

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

References ast_category_get().

00335 {
00336    return !!ast_category_get(config, category_name);
00337 }

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

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

00330 {
00331    return category_get(config, category_name, 0);
00332 }

struct ast_category* ast_category_new ( const char *  name  )  [read]

Definition at line 302 of file config.c.

References ast_calloc, and ast_category::name.

Referenced by config_odbc(), config_pgsql(), handle_updates(), process_text_line(), realtime_directory(), realtime_multi_odbc(), and realtime_multi_pgsql().

00303 {
00304    struct ast_category *category;
00305 
00306    if ((category = ast_calloc(1, sizeof(*category))))
00307       ast_copy_string(category->name, name, sizeof(category->name));
00308    return category;
00309 }

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

Definition at line 441 of file config.c.

References ast_category::name.

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

00442 {
00443    ast_copy_string(cat->name, name, sizeof(cat->name));
00444 }

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

References ast_category_get().

Referenced by realtime_peer().

00391 {
00392    struct ast_category *category = ast_category_get(config, cat);
00393    if (category)
00394       return category->root;
00395    return NULL;
00396 }

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

References find_engine().

Referenced by _sip_show_peer(), _sip_show_peers(), and sip_show_settings().

01416 {
01417    struct ast_config_engine *eng;
01418 
01419    eng = find_engine(family, NULL, 0, NULL, 0);
01420    if (eng)
01421       return 1;
01422    return 0;
01423 
01424 }

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

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

Referenced by __ast_http_load(), action_getconfig(), action_updateconfig(), adsi_load(), advanced_options(), aji_load_config(), ast_config_load(), ast_config_load_with_comments(), ast_enum_init(), ast_readconfig(), ast_rtp_reload(), ast_udptl_reload(), authenticate(), conf_exec(), directory_exec(), do_reload(), festival_exec(), find_conf(), handle_save_dialplan(), iax_provision_reload(), ind_load_module(), init_logger_chain(), init_manager(), load_config(), load_config_meetme(), load_module(), load_modules(), load_moh_classes(), load_odbc_config(), load_realtime_queue(), load_rpt_vars(), loadconfigurationfile(), my_load_module(), node_lookup(), odbc_load_module(), osp_load(), parse_config(), pbx_load_config(), pbx_load_users(), play_message(), privacy_exec(), read_agent_config(), read_config_maps(), realtime_directory(), realtime_peer(), realtime_switch_common(), reload(), reload_config(), reload_followme(), reload_queues(), rpt_master(), set_config(), setup_zap(), sla_load_config(), smdi_load(), tds_load_module(), unload_module(), and vm_forwardoptions().

00598 {
00599    struct ast_category *cat, *catn;
00600 
00601    if (!cfg)
00602       return;
00603 
00604    cat = cfg->root;
00605    while(cat) {
00606       catn = cat;
00607       cat = cat->next;
00608       ast_category_destroy(catn);
00609    }
00610    free(cfg);
00611 }

int ast_config_engine_deregister ( struct ast_config_engine del  ) 

Deegister config engine.

Definition at line 1264 of file config.c.

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

Referenced by unload_module().

01265 {
01266    struct ast_config_engine *ptr, *last=NULL;
01267 
01268    ast_mutex_lock(&config_lock);
01269 
01270    for (ptr = config_engine_list; ptr; ptr=ptr->next) {
01271       if (ptr == del) {
01272          if (last)
01273             last->next = ptr->next;
01274          else
01275             config_engine_list = ptr->next;
01276          break;
01277       }
01278       last = ptr;
01279    }
01280 
01281    ast_mutex_unlock(&config_lock);
01282 
01283    return 0;
01284 }

int ast_config_engine_register ( struct ast_config_engine newconfig  ) 

Register config engine.

Definition at line 1245 of file config.c.

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

Referenced by load_module().

01246 {
01247    struct ast_config_engine *ptr;
01248 
01249    ast_mutex_lock(&config_lock);
01250 
01251    if (!config_engine_list) {
01252       config_engine_list = new;
01253    } else {
01254       for (ptr = config_engine_list; ptr->next; ptr=ptr->next);
01255       ptr->next = new;
01256    }
01257 
01258    ast_mutex_unlock(&config_lock);
01259    ast_log(LOG_NOTICE,"Registered Config Engine %s\n", new->name);
01260 
01261    return 1;
01262 }

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

Definition at line 613 of file config.c.

References ast_config::current.

Referenced by config_odbc(), and config_text_file_load().

00614 {
00615    return cfg->current;
00616 }

struct ast_config* ast_config_internal_load ( const char *  configfile,
struct ast_config cfg,
int  withcomments 
) [read]

Definition at line 1326 of file config.c.

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

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

01327 {
01328    char db[256];
01329    char table[256];
01330    struct ast_config_engine *loader = &text_file_engine;
01331    struct ast_config *result; 
01332 
01333    if (cfg->include_level == cfg->max_include_level) {
01334       ast_log(LOG_WARNING, "Maximum Include level (%d) exceeded\n", cfg->max_include_level);
01335       return NULL;
01336    }
01337 
01338    cfg->include_level++;
01339 
01340    if (strcmp(filename, extconfig_conf) && strcmp(filename, "asterisk.conf") && config_engine_list) {
01341       struct ast_config_engine *eng;
01342 
01343       eng = find_engine(filename, db, sizeof(db), table, sizeof(table));
01344 
01345 
01346       if (eng && eng->load_func) {
01347          loader = eng;
01348       } else {
01349          eng = find_engine("global", db, sizeof(db), table, sizeof(table));
01350          if (eng && eng->load_func)
01351             loader = eng;
01352       }
01353    }
01354 
01355    result = loader->load_func(db, table, filename, cfg, withcomments);
01356 
01357    if (result)
01358       result->include_level--;
01359    else
01360       cfg->include_level--;
01361 
01362    return result;
01363 }

struct ast_config* ast_config_load ( const char *  filename  )  [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.
Returns NULL on error, or an ast_config data structure on success

Definition at line 1365 of file config.c.

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

Referenced by __ast_http_load(), __say_init(), adsi_load(), advanced_options(), aji_load_config(), ast_enum_init(), ast_readconfig(), ast_rtp_reload(), ast_udptl_reload(), authenticate(), conf_exec(), directory_exec(), do_reload(), festival_exec(), find_conf(), gtalk_load_config(), handle_save_dialplan(), iax_provision_reload(), ind_load_module(), init_logger_chain(), init_manager(), load_config(), load_config_meetme(), load_module(), load_modules(), load_moh_classes(), load_odbc_config(), load_rpt_vars(), loadconfigurationfile(), my_load_module(), node_lookup(), odbc_load_module(), osp_load(), parse_config(), pbx_load_config(), pbx_load_users(), play_message(), privacy_exec(), read_agent_config(), realtime_directory(), reload(), reload_config(), reload_followme(), reload_queues(), rpt_master(), set_config(), setup_zap(), sla_load_config(), smdi_load(), tds_load_module(), and vm_forwardoptions().

01366 {
01367    struct ast_config *cfg;
01368    struct ast_config *result;
01369 
01370    cfg = ast_config_new();
01371    if (!cfg)
01372       return NULL;
01373 
01374    result = ast_config_internal_load(filename, cfg, 0);
01375    if (!result)
01376       ast_config_destroy(cfg);
01377 
01378    return result;
01379 }

struct ast_config* ast_config_load_with_comments ( const char *  filename  )  [read]

Definition at line 1381 of file config.c.

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

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

01382 {
01383    struct ast_config *cfg;
01384    struct ast_config *result;
01385 
01386    cfg = ast_config_new();
01387    if (!cfg)
01388       return NULL;
01389 
01390    result = ast_config_internal_load(filename, cfg, 1);
01391    if (!result)
01392       ast_config_destroy(cfg);
01393 
01394    return result;
01395 }

struct ast_config* ast_config_new ( void   )  [read]

Definition at line 457 of file config.c.

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

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

00458 {
00459    struct ast_config *config;
00460 
00461    if ((config = ast_calloc(1, sizeof(*config))))
00462       config->max_include_level = MAX_INCLUDE_LEVEL;
00463    return config;
00464 }

const char* ast_config_option ( struct ast_config cfg,
const char *  cat,
const char *  var 
)

Definition at line 240 of file config.c.

References ast_variable_retrieve().

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

00241 {
00242    const char *tmp;
00243    tmp = ast_variable_retrieve(cfg, cat, var);
00244    if (!tmp)
00245       tmp = ast_variable_retrieve(cfg, "general", var);
00246    return tmp;
00247 }

void ast_config_set_current_category ( struct ast_config cfg,
const struct ast_category cat 
)

Definition at line 618 of file config.c.

References ast_config::current.

00619 {
00620    /* cast below is just to silence compiler warning about dropping "const" */
00621    cfg->current = (struct ast_category *) cat;
00622 }

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.

Definition at line 1397 of file config.c.

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

Referenced by cli_realtime_load(), find_conf_realtime(), find_user_realtime(), function_realtime_read(), load_realtime_queue(), realtime_alias(), realtime_exec(), realtime_peer(), realtime_switch_common(), realtime_user(), and update_realtime_member_field().

01398 {
01399    struct ast_config_engine *eng;
01400    char db[256]="";
01401    char table[256]="";
01402    struct ast_variable *res=NULL;
01403    va_list ap;
01404 
01405    va_start(ap, family);
01406    eng = find_engine(family, db, sizeof(db), table, sizeof(table));
01407    if (eng && eng->realtime_func) 
01408       res = eng->realtime_func(db, table, ap);
01409    va_end(ap);
01410 
01411    return res;
01412 }

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

Retrieve realtime configuration.

Parameters:
family which family/config to lookup This will use builtin configuration backends to look up a particular entity in realtime and return a variable list of its parameters. Unlike the ast_load_realtime, this function can return more than one entry and is thus stored inside a taditional ast_config structure rather than just returning a linked list of variables.

Definition at line 1426 of file config.c.

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

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

01427 {
01428    struct ast_config_engine *eng;
01429    char db[256]="";
01430    char table[256]="";
01431    struct ast_config *res=NULL;
01432    va_list ap;
01433 
01434    va_start(ap, family);
01435    eng = find_engine(family, db, sizeof(db), table, sizeof(table));
01436    if (eng && eng->realtime_multi_func) 
01437       res = eng->realtime_multi_func(db, table, ap);
01438    va_end(ap);
01439 
01440    return res;
01441 }

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 1443 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(), realtime_update_exec(), realtime_update_peer(), and update_realtime_member_field().

01444 {
01445    struct ast_config_engine *eng;
01446    int res = -1;
01447    char db[256]="";
01448    char table[256]="";
01449    va_list ap;
01450 
01451    va_start(ap, lookup);
01452    eng = find_engine(family, db, sizeof(db), table, sizeof(table));
01453    if (eng && eng->update_func) 
01454       res = eng->update_func(db, table, keyfield, lookup, ap);
01455    va_end(ap);
01456 
01457    return res;
01458 }

void ast_variable_append ( struct ast_category category,
struct ast_variable variable 
)

Definition at line 204 of file config.c.

Referenced by config_odbc(), config_pgsql(), handle_updates(), inherit_category(), move_variables(), process_text_line(), realtime_directory(), realtime_multi_odbc(), realtime_multi_pgsql(), and vm_change_password().

00205 {
00206    if (!variable)
00207       return;
00208    if (category->last)
00209       category->last->next = variable;
00210    else
00211       category->root = variable;
00212    category->last = variable;
00213    while (category->last->next)
00214       category->last = category->last->next;
00215 }

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

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

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

00467 {
00468    struct ast_variable *cur, *prev=NULL, *curn;
00469    int res = -1;
00470    cur = category->root;
00471    while (cur) {
00472       if (cur->name == variable) {
00473          if (prev) {
00474             prev->next = cur->next;
00475             if (cur == category->last)
00476                category->last = prev;
00477          } else {
00478             category->root = cur->next;
00479             if (cur == category->last)
00480                category->last = NULL;
00481          }
00482          cur->next = NULL;
00483          ast_variables_destroy(cur);
00484          return 0;
00485       }
00486       prev = cur;
00487       cur = cur->next;
00488    }
00489 
00490    prev = NULL;
00491    cur = category->root;
00492    while (cur) {
00493       curn = cur->next;
00494       if (!strcasecmp(cur->name, variable) && (ast_strlen_zero(match) || !strcasecmp(cur->value, match))) {
00495          if (prev) {
00496             prev->next = cur->next;
00497             if (cur == category->last)
00498                category->last = prev;
00499          } else {
00500             category->root = cur->next;
00501             if (cur == category->last)
00502                category->last = NULL;
00503          }
00504          cur->next = NULL;
00505          ast_variables_destroy(cur);
00506          res = 0;
00507       } else
00508          prev = cur;
00509 
00510       cur = curn;
00511    }
00512    return res;
00513 }

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

Definition at line 189 of file config.c.

References ast_calloc, ast_variable::name, ast_variable::stuff, and ast_variable::value.

Referenced by apply_outgoing(), ast_channeltype_list(), ast_httpd_helper_thread(), ast_variable_update(), astman_get_variables(), build_peer(), build_user(), check_access(), check_user_full(), config_odbc(), config_pgsql(), handle_updates(), handle_uri(), parkandannounce_exec(), process_text_line(), realtime_directory(), realtime_multi_odbc(), realtime_multi_pgsql(), realtime_odbc(), realtime_pgsql(), variable_clone(), and vm_change_password().

00190 {
00191    struct ast_variable *variable;
00192    int name_len = strlen(name) + 1; 
00193 
00194    if ((variable = ast_calloc(1, name_len + strlen(value) + 1 + sizeof(*variable)))) {
00195       variable->name = variable->stuff;
00196       variable->value = variable->stuff + name_len;      
00197       strcpy(variable->name,name);
00198       strcpy(variable->value,value);
00199    }
00200 
00201    return variable;
00202 }

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

Definition at line 250 of file config.c.

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

Referenced by advanced_options(), aji_load_config(), ast_config_option(), ast_rtp_reload(), ast_udptl_reload(), authenticate(), config_text_file_save(), directory_exec(), do_directory(), do_reload(), do_scheduler(), festival_exec(), find_queue_by_name_rt(), function_macro(), get_wait_interval(), gtalk_load_config(), handle_save_dialplan(), iax_template_parse(), ind_load_module(), init_acf_query(), init_logger_chain(), init_manager(), load_config(), load_config_meetme(), load_module(), load_modules(), load_rpt_vars(), node_lookup(), odbc_load_module(), osp_load(), parse_config(), pbx_load_config(), pbx_load_users(), play_message(), privacy_exec(), process_my_load_module(), read_agent_config(), realtime_directory(), realtime_peer(), reload_config(), reload_followme(), reload_queues(), retreive_memory(), retrieve_astcfgint(), rpt(), rpt_master(), rpt_tele_thread(), set_config(), setup_zap(), sla_build_station(), sla_build_trunk(), sla_load_config(), tds_load_module(), telem_lookup(), update_realtime_members(), vm_change_password(), and vm_forwardoptions().

00251 {
00252    struct ast_variable *v;
00253 
00254    if (category) {
00255       for (v = ast_variable_browse(config, category); v; v = v->next) {
00256          if (!strcasecmp(variable, v->name))
00257             return v->value;
00258       }
00259    } else {
00260       struct ast_category *cat;
00261 
00262       for (cat = config->root; cat; cat = cat->next)
00263          for (v = cat->root; v; v = v->next)
00264             if (!strcasecmp(variable, v->name))
00265                return v->value;
00266    }
00267 
00268    return NULL;
00269 }

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

Definition at line 515 of file config.c.

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

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

00517 {
00518    struct ast_variable *cur, *prev=NULL, *newer;
00519 
00520    if (!(newer = ast_variable_new(variable, value)))
00521       return -1;
00522    
00523    newer->object = object;
00524 
00525    for (cur = category->root; cur; prev = cur, cur = cur->next) {
00526       if (strcasecmp(cur->name, variable) ||
00527          (!ast_strlen_zero(match) && strcasecmp(cur->value, match)))
00528          continue;
00529 
00530       newer->next = cur->next;
00531       newer->object = cur->object || object;
00532       if (prev)
00533          prev->next = newer;
00534       else
00535          category->root = newer;
00536       if (category->last == cur)
00537          category->last = newer;
00538 
00539       cur->next = NULL;
00540       ast_variables_destroy(cur);
00541 
00542       return 0;
00543    }
00544 
00545    if (prev)
00546       prev->next = newer;
00547    else
00548       category->root = newer;
00549 
00550    return 0;
00551 }

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

References free, and ast_variable::next.

Referenced by __sip_destroy(), ast_category_destroy(), ast_httpd_helper_thread(), ast_pbx_outgoing_app2(), ast_pbx_outgoing_exten2(), ast_variable_delete(), ast_variable_update(), build_peer(), build_user(), find_conf_realtime(), find_user_realtime(), handle_uri(), iax2_destroy(), load_realtime_queue(), realtime_alias(), realtime_canmatch(), realtime_exec(), realtime_exists(), realtime_matchmore(), realtime_odbc(), realtime_peer(), realtime_user(), sip_alloc(), sip_destroy_peer(), sip_destroy_user(), and user_destructor().

00218 {
00219    struct ast_variable *vn;
00220 
00221    while(v) {
00222       vn = v;
00223       v = v->next;
00224       free(vn);
00225    }
00226 }

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

Definition at line 1000 of file config.c.

References ast_config_AST_CONFIG_DIR, AST_LIST_EMPTY, AST_LIST_LAST, AST_LIST_TRAVERSE, ast_log(), ast_variable_retrieve(), ast_verbose(), ast_variable::blanklines, ast_comment::cmt, errno, f, ast_category::ignored, LOG_DEBUG, ast_variable::name, ast_category_template_instance::name, ast_category::name, ast_variable::next, ast_comment::next, ast_variable::object, option_debug, option_verbose, ast_variable::precomments, ast_config::root, ast_variable::sameline, t, ast_variable::value, var, and VERBOSE_PREFIX_2.

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

01001 {
01002    FILE *f = NULL;
01003    int fd = -1;
01004    char fn[256], fntmp[256];
01005    char date[256]="";
01006    time_t t;
01007    struct ast_variable *var;
01008    struct ast_category *cat;
01009    struct ast_comment *cmt;
01010    struct stat s;
01011    int blanklines = 0;
01012 
01013    if (configfile[0] == '/') {
01014       snprintf(fntmp, sizeof(fntmp), "%s.XXXXXX", configfile);
01015       ast_copy_string(fn, configfile, sizeof(fn));
01016    } else {
01017       snprintf(fntmp, sizeof(fntmp), "%s/%s.XXXXXX", ast_config_AST_CONFIG_DIR, configfile);
01018       snprintf(fn, sizeof(fn), "%s/%s", ast_config_AST_CONFIG_DIR, configfile);
01019    }
01020    time(&t);
01021    ast_copy_string(date, ctime(&t), sizeof(date));
01022    if ((fd = mkstemp(fntmp)) > 0 && (f = fdopen(fd, "w")) != NULL) {
01023       if (option_verbose > 1)
01024          ast_verbose(VERBOSE_PREFIX_2 "Saving '%s': ", fn);
01025       fprintf(f, ";!\n");
01026       fprintf(f, ";! Automatically generated configuration file\n");
01027       if (strcmp(configfile, fn))
01028          fprintf(f, ";! Filename: %s (%s)\n", configfile, fn);
01029       else
01030          fprintf(f, ";! Filename: %s\n", configfile);
01031       fprintf(f, ";! Generator: %s\n", generator);
01032       fprintf(f, ";! Creation Date: %s", date);
01033       fprintf(f, ";!\n");
01034       cat = cfg->root;
01035       while(cat) {
01036          /* Dump section with any appropriate comment */
01037          for (cmt = cat->precomments; cmt; cmt=cmt->next)
01038          {
01039             if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
01040                fprintf(f,"%s", cmt->cmt);
01041          }
01042          if (!cat->precomments)
01043             fprintf(f,"\n");
01044          fprintf(f, "[%s]", cat->name);
01045          if (cat->ignored)
01046             fprintf(f, "(!)");
01047          if (!AST_LIST_EMPTY(&cat->template_instances)) {
01048             struct ast_category_template_instance *x;
01049             fprintf(f, "(");
01050             AST_LIST_TRAVERSE(&cat->template_instances, x, next) {
01051                fprintf(f,"%s",x->name);
01052                if (x != AST_LIST_LAST(&cat->template_instances))
01053                   fprintf(f,",");
01054             }
01055             fprintf(f, ")");
01056          }
01057          for(cmt = cat->sameline; cmt; cmt=cmt->next)
01058          {
01059             fprintf(f,"%s", cmt->cmt);
01060          }
01061          if (!cat->sameline)
01062             fprintf(f,"\n");
01063          var = cat->root;
01064          while(var) {
01065             struct ast_category_template_instance *x;
01066             int found = 0;
01067             AST_LIST_TRAVERSE(&cat->template_instances, x, next) {
01068                const char *pvalue = ast_variable_retrieve(cfg, x->name, var->name);
01069                if (pvalue && !strcmp(pvalue, var->value)) {
01070                   found = 1;
01071                   break;
01072                }
01073             }
01074             if (found) {
01075                var = var->next;
01076                continue;
01077             }
01078             for (cmt = var->precomments; cmt; cmt=cmt->next)
01079             {
01080                if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
01081                   fprintf(f,"%s", cmt->cmt);
01082             }
01083             if (var->sameline) 
01084                fprintf(f, "%s %s %s  %s", var->name, (var->object ? "=>" : "="), var->value, var->sameline->cmt);
01085             else  
01086                fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="), var->value);
01087             if (var->blanklines) {
01088                blanklines = var->blanklines;
01089                while (blanklines--)
01090                   fprintf(f, "\n");
01091             }
01092                
01093             var = var->next;
01094          }
01095 #if 0
01096          /* Put an empty line */
01097          fprintf(f, "\n");
01098 #endif
01099          cat = cat->next;
01100       }
01101       if ((option_verbose > 1) && !option_debug)
01102          ast_verbose("Saved\n");
01103    } else {
01104       if (option_debug)
01105          ast_log(LOG_DEBUG, "Unable to open for writing: %s (%s)\n", fn, strerror(errno));
01106       if (option_verbose > 1)
01107          ast_verbose(VERBOSE_PREFIX_2 "Unable to write %s (%s)", fn, strerror(errno));
01108       if (fd > -1)
01109          close(fd);
01110       return -1;
01111    }
01112    stat(fn, &s);
01113    fchmod(fd, s.st_mode);
01114    fclose(f);
01115    if (unlink(fn) || link(fntmp, fn)) {
01116       if (option_debug)
01117          ast_log(LOG_DEBUG, "Unable to open for writing: %s (%s)\n", fn, strerror(errno));
01118       if (option_verbose > 1)
01119          ast_verbose(VERBOSE_PREFIX_2 "Unable to write %s (%s)", fn, strerror(errno));
01120       unlink(fntmp);
01121       return -1;
01122    }
01123    unlink(fntmp);
01124    return 0;
01125 }

int read_config_maps ( void   ) 

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

01178 {
01179    struct ast_config *config, *configtmp;
01180    struct ast_variable *v;
01181    char *driver, *table, *database, *stringp, *tmp;
01182 
01183    clear_config_maps();
01184 
01185    configtmp = ast_config_new();
01186    configtmp->max_include_level = 1;
01187    config = ast_config_internal_load(extconfig_conf, configtmp, 0);
01188    if (!config) {
01189       ast_config_destroy(configtmp);
01190       return 0;
01191    }
01192 
01193    for (v = ast_variable_browse(config, "settings"); v; v = v->next) {
01194       stringp = v->value;
01195       driver = strsep(&stringp, ",");
01196 
01197       if ((tmp = strchr(stringp, '\"')))
01198          stringp = tmp;
01199 
01200       /* check if the database text starts with a double quote */
01201       if (*stringp == '"') {
01202          stringp++;
01203          database = strsep(&stringp, "\"");
01204          strsep(&stringp, ",");
01205       } else {
01206          /* apparently this text has no quotes */
01207          database = strsep(&stringp, ",");
01208       }
01209 
01210       table = strsep(&stringp, ",");
01211 
01212       if (!strcmp(v->name, extconfig_conf)) {
01213          ast_log(LOG_WARNING, "Cannot bind '%s'!\n", extconfig_conf);
01214          continue;
01215       }
01216 
01217       if (!strcmp(v->name, "asterisk.conf")) {
01218          ast_log(LOG_WARNING, "Cannot bind 'asterisk.conf'!\n");
01219          continue;
01220       }
01221 
01222       if (!strcmp(v->name, "logger.conf")) {
01223          ast_log(LOG_WARNING, "Cannot bind 'logger.conf'!\n");
01224          continue;
01225       }
01226 
01227       if (!driver || !database)
01228          continue;
01229       if (!strcasecmp(v->name, "sipfriends")) {
01230          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");
01231          append_mapping("sipusers", driver, database, table ? table : "sipfriends");
01232          append_mapping("sippeers", driver, database, table ? table : "sipfriends");
01233       } else if (!strcasecmp(v->name, "iaxfriends")) {
01234          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");
01235          append_mapping("iaxusers", driver, database, table ? table : "iaxfriends");
01236          append_mapping("iaxpeers", driver, database, table ? table : "iaxfriends");
01237       } else 
01238          append_mapping(v->name, driver, database, table);
01239    }
01240       
01241    ast_config_destroy(config);
01242    return 0;
01243 }

int register_config_cli ( void   ) 

Definition at line 1498 of file config.c.

References ast_cli_register_multiple().

Referenced by main().

01499 {
01500    ast_cli_register_multiple(cli_config, sizeof(cli_config) / sizeof(struct ast_cli_entry));
01501    return 0;
01502 }


Generated on Fri Sep 25 19:28:34 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.5