Codename Pineapple

Home page | Mailing list | Docs

Last updated: Sat Feb 3 05:01:29 2007

Asterisk developer's documentation :: Codename Pineapple


config.h File Reference


Detailed Description

Configuration File Parser.

Definition in file config.h.

#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, int withcomments)
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, const 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, int withcomments)
ast_configast_config_load (const char *filename)
 Load a config file.
ast_configast_config_load_with_comments (const char *filename)
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)
ast_variableast_load_realtime (const char *family,...)
 Retrieve realtime configuration.
ast_variableast_load_realtime_all (const char *family,...)
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_category *category, const char *variable, const char *match)
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)
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)


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 config, and ast_category::include_level.

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

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

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

Referenced by action_getconfig(), aji_load_config(), authenticate(), complete_sipnotify(), gtalk_load_config(), iax_provision_reload(), ind_load_module(), jingle_load_config(), load_config(), load_module(), load_moh_classes(), load_odbc_config(), pbx_load_users(), read_agent_config(), realtime_switch_common(), reload(), reload_config(), set_config(), and setup_zap().

00364 {  
00365    struct ast_category *cat = NULL;
00366 
00367    if (prev && config->last_browse && (config->last_browse->name == prev))
00368       cat = config->last_browse->next;
00369    else if (!prev && config->root)
00370       cat = config->root;
00371    else if (prev) {
00372       for (cat = config->root; cat; cat = cat->next) {
00373          if (cat->name == prev) {
00374             cat = cat->next;
00375             break;
00376          }
00377       }
00378       if (!cat) {
00379          for (cat = config->root; cat; cat = cat->next) {
00380             if (!strcasecmp(cat->name, prev)) {
00381                cat = cat->next;
00382                break;
00383             }
00384          }
00385       }
00386    }
00387    
00388    if (cat)
00389       cat = next_available_category(cat);
00390 
00391    config->last_browse = cat;
00392    return (cat) ? cat->name : NULL;
00393 }

int ast_category_delete struct ast_config cfg,
const char *  category
 

Definition at line 528 of file config.c.

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

Referenced by handle_updates().

00529 {
00530    struct ast_category *prev=NULL, *cat;
00531    cat = cfg->root;
00532    while (cat) {
00533       if (cat->name == category) {
00534          ast_variables_destroy(cat->root);
00535          if (prev) {
00536             prev->next = cat->next;
00537             if (cat == cfg->last)
00538                cfg->last = prev;
00539          } else {
00540             cfg->root = cat->next;
00541             if (cat == cfg->last)
00542                cfg->last = NULL;
00543          }
00544          free(cat);
00545          return 0;
00546       }
00547       prev = cat;
00548       cat = cat->next;
00549    }
00550 
00551    prev = NULL;
00552    cat = cfg->root;
00553    while (cat) {
00554       if (!strcasecmp(cat->name, category)) {
00555          ast_variables_destroy(cat->root);
00556          if (prev) {
00557             prev->next = cat->next;
00558             if (cat == cfg->last)
00559                cfg->last = prev;
00560          } else {
00561             cfg->root = cat->next;
00562             if (cat == cfg->last)
00563                cfg->last = NULL;
00564          }
00565          free(cat);
00566          return 0;
00567       }
00568       prev = cat;
00569       cat = cat->next;
00570    }
00571    return -1;
00572 }

void ast_category_destroy struct ast_category cat  ) 
 

Definition at line 350 of file config.c.

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

Referenced by process_text_line(), and realtime_multi_odbc().

00351 {
00352    ast_variables_destroy(cat->root);
00353    free(cat);
00354 }

struct ast_variable* ast_category_detach_variables struct ast_category cat  ) 
 

Definition at line 395 of file config.c.

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

Referenced by realtime_switch_common().

00396 {
00397    struct ast_variable *v;
00398 
00399    v = cat->root;
00400    cat->root = NULL;
00401    cat->last = NULL;
00402 
00403    return v;
00404 }

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

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
 

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

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

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

struct ast_category* ast_category_new const char *  name  ) 
 

Definition at line 302 of file config.c.

References ast_calloc.

Referenced by config_odbc(), config_pgsql(), handle_updates(), process_text_line(), 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 406 of file config.c.

References ast_category::name.

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

00407 {
00408    ast_copy_string(cat->name, name, sizeof(cat->name));
00409 }

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

References find_engine().

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

01377 {
01378    struct ast_config_engine *eng;
01379 
01380    eng = find_engine(family, NULL, 0, NULL, 0);
01381    if (eng)
01382       return 1;
01383    return 0;
01384 
01385 }

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

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

Referenced by action_getconfig(), action_updateconfig(), ast_config_load(), ast_config_load_with_comments(), ast_enum_init(), ast_rtp_reload(), ast_udptl_reload(), do_reload(), handle_save_dialplan(), iax_provision_reload(), ind_load_module(), load_config(), load_module(), parse_config(), process_text_line(), read_agent_config(), read_config_maps(), realtime_switch_common(), reload_config(), set_config(), and setup_zap().

00575 {
00576    struct ast_category *cat, *catn;
00577 
00578    if (!cfg)
00579       return;
00580 
00581    cat = cfg->root;
00582    while (cat) {
00583       ast_variables_destroy(cat->root);
00584       catn = cat;
00585       cat = cat->next;
00586       free(catn);
00587    }
00588    free(cfg);
00589 }

int ast_config_engine_deregister struct ast_config_engine del  ) 
 

Deegister config engine.

Definition at line 1189 of file config.c.

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

Referenced by unload_module().

01190 {
01191    struct ast_config_engine *ptr, *last=NULL;
01192 
01193    ast_mutex_lock(&config_lock);
01194 
01195    for (ptr = config_engine_list; ptr; ptr=ptr->next) {
01196       if (ptr == del) {
01197          if (last)
01198             last->next = ptr->next;
01199          else
01200             config_engine_list = ptr->next;
01201          break;
01202       }
01203       last = ptr;
01204    }
01205 
01206    ast_mutex_unlock(&config_lock);
01207 
01208    return 0;
01209 }

int ast_config_engine_register struct ast_config_engine newconfig  ) 
 

Register config engine.

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

01171 {
01172    struct ast_config_engine *ptr;
01173 
01174    ast_mutex_lock(&config_lock);
01175 
01176    if (!config_engine_list) {
01177       config_engine_list = new;
01178    } else {
01179       for (ptr = config_engine_list; ptr->next; ptr=ptr->next);
01180       ptr->next = new;
01181    }
01182 
01183    ast_mutex_unlock(&config_lock);
01184    ast_log(LOG_NOTICE,"Registered Config Engine %s\n", new->name);
01185 
01186    return 1;
01187 }

struct ast_category* ast_config_get_current_category const struct ast_config cfg  ) 
 

Definition at line 591 of file config.c.

References ast_config::current.

Referenced by config_odbc(), and config_text_file_load().

00592 {
00593    return cfg->current;
00594 }

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

Definition at line 1251 of file config.c.

References ast_log(), config_engine_list, find_engine(), ast_config::include_level, ast_config_engine::load_func, LOG_WARNING, ast_config::max_include_level, and text_file_engine.

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

01252 {
01253    char db[256];
01254    char table[256];
01255    struct ast_config_engine *loader = &text_file_engine;
01256    struct ast_config *result; 
01257 
01258    if (cfg->include_level == cfg->max_include_level) {
01259       ast_log(LOG_WARNING, "Maximum Include level (%d) exceeded\n", cfg->max_include_level);
01260       return NULL;
01261    }
01262 
01263    cfg->include_level++;
01264 
01265    if (strcmp(filename, extconfig_conf) && strcmp(filename, "asterisk.conf") && config_engine_list) {
01266       struct ast_config_engine *eng;
01267 
01268       eng = find_engine(filename, db, sizeof(db), table, sizeof(table));
01269 
01270 
01271       if (eng && eng->load_func) {
01272          loader = eng;
01273       } else {
01274          eng = find_engine("global", db, sizeof(db), table, sizeof(table));
01275          if (eng && eng->load_func)
01276             loader = eng;
01277       }
01278    }
01279 
01280    result = loader->load_func(db, table, filename, cfg, withcomments);
01281 
01282    if (result)
01283       result->include_level--;
01284 
01285    return result;
01286 }

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

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

Referenced by __ast_http_load(), adsi_load(), aji_load_config(), ast_enum_init(), ast_readconfig(), ast_rtp_reload(), ast_udptl_reload(), authenticate(), do_reload(), gtalk_load_config(), handle_save_dialplan(), iax_provision_reload(), ind_load_module(), init_logger_chain(), init_manager(), jingle_load_config(), load_config(), load_module(), load_modules(), load_moh_classes(), load_odbc_config(), parse_config(), pbx_load_config(), pbx_load_users(), read_agent_config(), reload(), reload_config(), set_config(), setup_zap(), and smdi_load().

01289 {
01290    struct ast_config *cfg;
01291    struct ast_config *result;
01292 
01293    cfg = ast_config_new();
01294    if (!cfg)
01295       return NULL;
01296 
01297    result = ast_config_internal_load(filename, cfg, 0);
01298    if (!result)
01299       ast_config_destroy(cfg);
01300 
01301    return result;
01302 }

struct ast_config* ast_config_load_with_comments const char *  filename  ) 
 

Definition at line 1304 of file config.c.

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

Referenced by action_getconfig(), and action_updateconfig().

01305 {
01306    struct ast_config *cfg;
01307    struct ast_config *result;
01308 
01309    cfg = ast_config_new();
01310    if (!cfg)
01311       return NULL;
01312 
01313    result = ast_config_internal_load(filename, cfg, 1);
01314    if (!result)
01315       ast_config_destroy(cfg);
01316 
01317    return result;
01318 }

struct ast_config* ast_config_new void   ) 
 

Definition at line 419 of file config.c.

References ast_calloc, config, and MAX_INCLUDE_LEVEL.

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

00420 {
00421    struct ast_config *config;
00422 
00423    if ((config = ast_calloc(1, sizeof(*config))))
00424       config->max_include_level = MAX_INCLUDE_LEVEL;
00425    return config;
00426 }

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

References ast_config::current.

00597 {
00598    /* cast below is just to silence compiler warning about dropping "const" */
00599    cfg->current = (struct ast_category *) cat;
00600 }

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

Definition at line 1346 of file config.c.

References ast_load_realtime_helper(), free, and ast_variable::next.

Referenced by realtime_alias(), realtime_peer(), realtime_switch_common(), and realtime_user().

01347 {
01348    struct ast_variable *res, *cur, *prev = NULL, *freeme = NULL;
01349    va_list ap;
01350 
01351    va_start(ap, family);
01352    res = ast_load_realtime_helper(family, ap);
01353    va_end(ap);
01354 
01355    /* Eliminate blank entries */
01356    for (cur = res; cur; cur = cur->next) {
01357       if (freeme) {
01358          free(freeme);
01359          freeme = NULL;
01360       }
01361 
01362       if (ast_strlen_zero(cur->value)) {
01363          if (prev)
01364             prev->next = cur->next;
01365          else
01366             res = cur->next;
01367          freeme = cur;
01368       } else {
01369          prev = cur;
01370       }
01371    }
01372    return res;
01373 }

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

Definition at line 1334 of file config.c.

References ast_load_realtime_helper().

Referenced by cli_realtime_load().

01335 {
01336    struct ast_variable *res;
01337    va_list ap;
01338 
01339    va_start(ap, family);
01340    res = ast_load_realtime_helper(family, ap);
01341    va_end(ap);
01342 
01343    return res;
01344 }

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

References find_engine(), and ast_config_engine::realtime_multi_func.

Referenced by realtime_switch_common().

01388 {
01389    struct ast_config_engine *eng;
01390    char db[256]="";
01391    char table[256]="";
01392    struct ast_config *res=NULL;
01393    va_list ap;
01394 
01395    va_start(ap, family);
01396    eng = find_engine(family, db, sizeof(db), table, sizeof(table));
01397    if (eng && eng->realtime_multi_func) 
01398       res = eng->realtime_multi_func(db, table, ap);
01399    va_end(ap);
01400 
01401    return res;
01402 }

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

References find_engine(), and ast_config_engine::update_func.

Referenced by cli_realtime_update(), destroy_association(), and realtime_update_peer().

01405 {
01406    struct ast_config_engine *eng;
01407    int res = -1;
01408    char db[256]="";
01409    char table[256]="";
01410    va_list ap;
01411 
01412    va_start(ap, lookup);
01413    eng = find_engine(family, db, sizeof(db), table, sizeof(table));
01414    if (eng && eng->update_func) 
01415       res = eng->update_func(db, table, keyfield, lookup, ap);
01416    va_end(ap);
01417 
01418    return res;
01419 }

void ast_variable_append struct ast_category category,
struct ast_variable variable
 

Definition at line 204 of file config.c.

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

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

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
 

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

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

Referenced by __ast_http_load(), action_getconfig(), adsi_load(), aji_load_config(), ast_enum_init(), ast_readconfig(), ast_variable_retrieve(), authenticate(), gtalk_load_config(), handle_save_dialplan(), iax_template_parse(), ind_load_module(), init_logger_chain(), init_manager(), jingle_load_config(), load_config(), load_module(), load_modules(), load_moh_classes(), load_odbc_config(), pbx_load_config(), read_agent_config(), read_config_maps(), reload(), reload_config(), set_config(), setup_zap(), sip_notify(), smdi_load(), and store_config().

00229 {
00230    struct ast_category *cat = NULL;
00231 
00232    if (category && config->last_browse && (config->last_browse->name == category))
00233       cat = config->last_browse;
00234    else
00235       cat = ast_category_get(config, category);
00236 
00237    return (cat) ? cat->root : NULL;
00238 }

int ast_variable_delete struct ast_category category,
const char *  variable,
const char *  match
 

Definition at line 428 of file config.c.

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

Referenced by handle_updates().

00429 {
00430    struct ast_variable *cur, *prev=NULL, *curn;
00431    int res = -1;
00432    cur = category->root;
00433    while (cur) {
00434       if (cur->name == variable) {
00435          if (prev) {
00436             prev->next = cur->next;
00437             if (cur == category->last)
00438                category->last = prev;
00439          } else {
00440             category->root = cur->next;
00441             if (cur == category->last)
00442                category->last = NULL;
00443          }
00444          cur->next = NULL;
00445          ast_variables_destroy(cur);
00446          return 0;
00447       }
00448       prev = cur;
00449       cur = cur->next;
00450    }
00451 
00452    prev = NULL;
00453    cur = category->root;
00454    while (cur) {
00455       curn = cur->next;
00456       if (!strcasecmp(cur->name, variable) && (ast_strlen_zero(match) || !strcasecmp(cur->value, match))) {
00457          if (prev) {
00458             prev->next = cur->next;
00459             if (cur == category->last)
00460                category->last = prev;
00461          } else {
00462             category->root = cur->next;
00463             if (cur == category->last)
00464                category->last = NULL;
00465          }
00466          cur->next = NULL;
00467          ast_variables_destroy(cur);
00468          res = 0;
00469       } else
00470          prev = cur;
00471 
00472       cur = curn;
00473    }
00474    return res;
00475 }

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

Definition at line 189 of file config.c.

References ast_calloc, and ast_variable::name.

Referenced by add_var(), apply_outgoing(), ast_channeltype_list(), ast_variable_update(), astman_get_variables(), build_user(), check_access(), check_user_full(), config_odbc(), config_pgsql(), copy_vars(), handle_updates(), handle_uri(), httpd_helper_thread(), iax_parse_ies(), process_text_line(), realtime_multi_odbc(), realtime_multi_pgsql(), realtime_odbc(), realtime_pgsql(), and variable_clone().

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(), config, ast_variable::name, ast_variable::next, and ast_variable::value.

Referenced by aji_load_config(), ast_config_option(), ast_rtp_reload(), ast_udptl_reload(), do_reload(), gtalk_load_config(), handle_save_dialplan(), iax_template_parse(), ind_load_module(), init_logger_chain(), jingle_load_config(), parse_config(), pbx_load_config(), pbx_load_users(), read_agent_config(), reload_config(), set_config(), and setup_zap().

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
 

Definition at line 477 of file config.c.

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

Referenced by handle_updates().

00478 {
00479    struct ast_variable *cur, *prev=NULL, *newer;
00480    newer = ast_variable_new(variable, value);
00481    if (!newer)
00482       return -1;
00483    cur = category->root;
00484    while (cur) {
00485       if (cur->name == variable) {
00486          newer->next = cur->next;
00487          newer->object = cur->object;
00488          if (prev)
00489             prev->next = newer;
00490          else
00491             category->root = newer;
00492          if (category->last == cur)
00493             category->last = newer;
00494          cur->next = NULL;
00495          ast_variables_destroy(cur);
00496          return 0;
00497       }
00498       prev = cur;
00499       cur = cur->next;
00500    }
00501 
00502    prev = NULL;
00503    cur = category->root;
00504    while (cur) {
00505       if (!strcasecmp(cur->name, variable) && (ast_strlen_zero(match) || !strcasecmp(cur->value, match))) {
00506          newer->next = cur->next;
00507          newer->object = cur->object;
00508          if (prev)
00509             prev->next = newer;
00510          else
00511             category->root = newer;
00512          if (category->last == cur)
00513             category->last = newer;
00514          cur->next = NULL;
00515          ast_variables_destroy(cur);
00516          return 0;
00517       }
00518       prev = cur;
00519       cur = cur->next;
00520    }
00521    if (prev)
00522       prev->next = newer;
00523    else
00524       category->root = newer;
00525    return 0;
00526 }

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 ast_category_delete(), ast_category_destroy(), ast_config_destroy(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_variable_delete(), ast_variable_update(), build_device(), build_peer(), build_user(), destroy_user(), handle_uri(), httpd_helper_thread(), iax2_destroy(), realtime_alias(), realtime_canmatch(), realtime_exec(), realtime_exists(), realtime_matchmore(), realtime_odbc(), realtime_peer(), realtime_user(), sip_alloc(), sip_destroy_device(), sip_destroy_peer(), sip_destroy_user(), and socket_process().

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

References ast_config_AST_CONFIG_DIR, ast_log(), ast_verbose(), ast_comment::cmt, LOG_DEBUG, ast_category::name, ast_category::next, option_debug, option_verbose, ast_category::precomments, ast_category::root, ast_config::root, ast_category::sameline, var, and VERBOSE_PREFIX_2.

Referenced by action_updateconfig().

00964 {
00965    FILE *f;
00966    char fn[256];
00967    char date[256]="";
00968    time_t t;
00969    struct ast_variable *var;
00970    struct ast_category *cat;
00971    struct ast_comment *cmt;
00972    int blanklines = 0;
00973 
00974    if (configfile[0] == '/') {
00975       ast_copy_string(fn, configfile, sizeof(fn));
00976    } else {
00977       snprintf(fn, sizeof(fn), "%s/%s", ast_config_AST_CONFIG_DIR, configfile);
00978    }
00979    time(&t);
00980    ast_copy_string(date, ctime(&t), sizeof(date));
00981 #ifdef __CYGWIN__ 
00982    if ((f = fopen(fn, "w+"))) {
00983 #else
00984    if ((f = fopen(fn, "w"))) {
00985 #endif       
00986       if (option_verbose > 1)
00987          ast_verbose(VERBOSE_PREFIX_2 "Saving '%s': ", fn);
00988       fprintf(f, ";!\n");
00989       fprintf(f, ";! Automatically generated configuration file\n");
00990       if (strcmp(configfile, fn))
00991          fprintf(f, ";! Filename: %s (%s)\n", configfile, fn);
00992       else
00993          fprintf(f, ";! Filename: %s\n", configfile);
00994       fprintf(f, ";! Generator: %s\n", generator);
00995       fprintf(f, ";! Creation Date: %s", date);
00996       fprintf(f, ";!\n");
00997       cat = cfg->root;
00998       while (cat) {
00999          /* Dump section with any appropriate comment */
01000          for (cmt = cat->precomments; cmt; cmt=cmt->next)
01001          {
01002             if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
01003                fprintf(f,"%s", cmt->cmt);
01004          }
01005          if (!cat->precomments)
01006             fprintf(f,"\n");
01007          fprintf(f, "[%s]", cat->name);
01008          for (cmt = cat->sameline; cmt; cmt=cmt->next)
01009          {
01010             fprintf(f,"%s", cmt->cmt);
01011          }
01012          if (!cat->sameline)
01013             fprintf(f,"\n");
01014          var = cat->root;
01015          while (var) {
01016             for (cmt = var->precomments; cmt; cmt=cmt->next)
01017             {
01018                if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
01019                   fprintf(f,"%s", cmt->cmt);
01020             }
01021             if (var->sameline) 
01022                fprintf(f, "%s %s %s  %s", var->name, (var->object ? "=>" : "="), var->value, var->sameline->cmt);
01023             else  
01024                fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="), var->value);
01025             if (var->blanklines) {
01026                blanklines = var->blanklines;
01027                while (blanklines--)
01028                   fprintf(f, "\n");
01029             }
01030                
01031             var = var->next;
01032          }
01033 #if 0
01034          /* Put an empty line */
01035          fprintf(f, "\n");
01036 #endif
01037          cat = cat->next;
01038       }
01039       if ((option_verbose > 1) && !option_debug)
01040          ast_verbose("Saved\n");
01041    } else {
01042       if (option_debug)
01043          ast_log(LOG_DEBUG, "Unable to open for writing: %s\n", fn);
01044       if (option_verbose > 1)
01045          ast_verbose(VERBOSE_PREFIX_2 "Unable to write (%s)", strerror(errno));
01046       return -1;
01047    }
01048    fclose(f);
01049    return 0;
01050 }

int read_config_maps void   ) 
 

Definition at line 1102 of file config.c.

References ast_config_destroy(), ast_config_internal_load(), ast_config_new(), ast_variable_browse(), clear_config_maps(), config, ast_config::max_include_level, ast_variable::next, strsep(), and ast_variable::value.

01103 {
01104    struct ast_config *config, *configtmp;
01105    struct ast_variable *v;
01106    char *driver, *table, *database, *stringp, *tmp;
01107 
01108    clear_config_maps();
01109 
01110    configtmp = ast_config_new();
01111    configtmp->max_include_level = 1;
01112    config = ast_config_internal_load(extconfig_conf, configtmp, 0);
01113    if (!config) {
01114       ast_config_destroy(configtmp);
01115       return 0;
01116    }
01117 
01118    for (v = ast_variable_browse(config, "settings"); v; v = v->next) {
01119       stringp = v->value;
01120       driver = strsep(&stringp, ",");
01121 
01122       if ((tmp = strchr(stringp, '\"')))
01123          stringp = tmp;
01124 
01125       /* check if the database text starts with a double quote */
01126       if (*stringp == '"') {
01127          stringp++;
01128          database = strsep(&stringp, "\"");
01129          strsep(&stringp, ",");
01130       } else {
01131          /* apparently this text has no quotes */
01132          database = strsep(&stringp, ",");
01133       }
01134 
01135       table = strsep(&stringp, ",");
01136 
01137       if (!strcmp(v->name, extconfig_conf)) {
01138          ast_log(LOG_WARNING, "Cannot bind '%s'!\n", extconfig_conf);
01139          continue;
01140       }
01141 
01142       if (!strcmp(v->name, "asterisk.conf")) {
01143          ast_log(LOG_WARNING, "Cannot bind 'asterisk.conf'!\n");
01144          continue;
01145       }
01146 
01147       if (!strcmp(v->name, "logger.conf")) {
01148          ast_log(LOG_WARNING, "Cannot bind 'logger.conf'!\n");
01149          continue;
01150       }
01151 
01152       if (!driver || !database)
01153          continue;
01154       if (!strcasecmp(v->name, "sipfriends")) {
01155          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");
01156          append_mapping("sipusers", driver, database, table ? table : "sipfriends");
01157          append_mapping("sippeers", driver, database, table ? table : "sipfriends");
01158       } else if (!strcasecmp(v->name, "iaxfriends")) {
01159          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");
01160          append_mapping("iaxusers", driver, database, table ? table : "iaxfriends");
01161          append_mapping("iaxpeers", driver, database, table ? table : "iaxfriends");
01162       } else 
01163          append_mapping(v->name, driver, database, table);
01164    }
01165       
01166    ast_config_destroy(config);
01167    return 0;
01168 }

int register_config_cli void   ) 
 

Definition at line 1454 of file config.c.

References ast_cli_register_multiple(), and cli_config.

01455 {
01456    ast_cli_register_multiple(cli_config, sizeof(cli_config) / sizeof(struct ast_cli_entry));
01457    return 0;
01458 }


Asterisk is a trademark for Digium, inc.. | Edvina.net | Asterisk.org | This documentation was generated with Doxygen