#include <stdarg.h>
Go to the source code of this file.
Data Structures | |
struct | ast_config_engine |
struct | ast_variable |
Typedefs | |
typedef struct ast_config * | config_load_func (const char *database, const char *table, const char *configfile, struct ast_config *config, int withcomments) |
typedef struct ast_config * | realtime_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_variable * | realtime_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_variable * | ast_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_category * | ast_category_get (const struct ast_config *config, const char *category_name) |
Retrieve a category if it exists. | |
struct ast_category * | ast_category_new (const char *name) |
void | ast_category_rename (struct ast_category *cat, const char *name) |
struct ast_variable * | ast_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_category * | ast_config_get_current_category (const struct ast_config *cfg) |
struct ast_config * | ast_config_internal_load (const char *configfile, struct ast_config *cfg, int withcomments) |
struct ast_config * | ast_config_load (const char *filename) |
Load a config file. | |
struct ast_config * | ast_config_load_with_comments (const char *filename) |
struct ast_config * | ast_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_variable * | ast_load_realtime (const char *family,...) |
Retrieve realtime configuration. | |
struct ast_config * | ast_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_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. | |
int | ast_variable_delete (struct ast_category *category, char *variable, char *match) |
struct ast_variable * | ast_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) |
Definition in file config.h.
typedef struct ast_config* config_load_func(const char *database, const char *table, const char *configfile, struct ast_config *config, int withcomments) |
typedef struct ast_config* realtime_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_variable* realtime_var_get(const char *database, const char *table, va_list ap) |
void ast_category_append | ( | struct ast_config * | config, | |
struct ast_category * | cat | |||
) |
Definition at line 332 of file config.c.
References ast_config::current, ast_config::include_level, ast_category::include_level, ast_config::last, ast_category::next, and ast_config::root.
00333 { 00334 if (config->last) 00335 config->last->next = category; 00336 else 00337 config->root = category; 00338 category->include_level = config->include_level; 00339 config->last = category; 00340 config->current = category; 00341 }
char* ast_category_browse | ( | struct ast_config * | config, | |
const char * | prev | |||
) |
Goes through categories.
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. |
Definition at line 364 of file config.c.
References ast_config::last_browse, ast_category::name, ast_category::next, next_available_category(), and ast_config::root.
00365 { 00366 struct ast_category *cat = NULL; 00367 00368 if (prev && config->last_browse && (config->last_browse->name == prev)) 00369 cat = config->last_browse->next; 00370 else if (!prev && config->root) 00371 cat = config->root; 00372 else if (prev) { 00373 for (cat = config->root; cat; cat = cat->next) { 00374 if (cat->name == prev) { 00375 cat = cat->next; 00376 break; 00377 } 00378 } 00379 if (!cat) { 00380 for (cat = config->root; cat; cat = cat->next) { 00381 if (!strcasecmp(cat->name, prev)) { 00382 cat = cat->next; 00383 break; 00384 } 00385 } 00386 } 00387 } 00388 00389 if (cat) 00390 cat = next_available_category(cat); 00391 00392 config->last_browse = cat; 00393 return (cat) ? cat->name : NULL; 00394 }
int ast_category_delete | ( | struct ast_config * | cfg, | |
char * | category | |||
) |
Definition at line 516 of file config.c.
References ast_variables_destroy(), free, ast_config::last, ast_category::next, and ast_config::root.
00517 { 00518 struct ast_category *prev=NULL, *cat; 00519 cat = cfg->root; 00520 while(cat) { 00521 if (cat->name == category) { 00522 ast_variables_destroy(cat->root); 00523 if (prev) { 00524 prev->next = cat->next; 00525 if (cat == cfg->last) 00526 cfg->last = prev; 00527 } else { 00528 cfg->root = cat->next; 00529 if (cat == cfg->last) 00530 cfg->last = NULL; 00531 } 00532 free(cat); 00533 return 0; 00534 } 00535 prev = cat; 00536 cat = cat->next; 00537 } 00538 00539 prev = NULL; 00540 cat = cfg->root; 00541 while(cat) { 00542 if (!strcasecmp(cat->name, category)) { 00543 ast_variables_destroy(cat->root); 00544 if (prev) { 00545 prev->next = cat->next; 00546 if (cat == cfg->last) 00547 cfg->last = prev; 00548 } else { 00549 cfg->root = cat->next; 00550 if (cat == cfg->last) 00551 cfg->last = NULL; 00552 } 00553 free(cat); 00554 return 0; 00555 } 00556 prev = cat; 00557 cat = cat->next; 00558 } 00559 return -1; 00560 }
void ast_category_destroy | ( | struct ast_category * | cat | ) |
Definition at line 343 of file config.c.
References ast_variables_destroy(), free, and ast_category::root.
00344 { 00345 ast_variables_destroy(cat->root); 00346 free(cat); 00347 }
struct ast_variable* ast_category_detach_variables | ( | struct ast_category * | cat | ) | [read] |
Definition at line 396 of file config.c.
References ast_category::last, and ast_category::root.
00397 { 00398 struct ast_variable *v; 00399 00400 v = cat->root; 00401 cat->root = NULL; 00402 cat->last = NULL; 00403 00404 return v; 00405 }
int ast_category_exist | ( | const struct ast_config * | config, | |
const char * | category_name | |||
) |
Check for category duplicates.
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. |
Definition at line 327 of file config.c.
References ast_category_get().
00328 { 00329 return !!ast_category_get(config, category_name); 00330 }
struct ast_category* ast_category_get | ( | const struct ast_config * | config, | |
const char * | category_name | |||
) | [read] |
Retrieve a category if it exists.
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. |
Definition at line 322 of file config.c.
References category_get().
00323 { 00324 return category_get(config, category_name, 0); 00325 }
struct ast_category* ast_category_new | ( | const char * | name | ) | [read] |
Definition at line 295 of file config.c.
References ast_calloc, and ast_category::name.
00296 { 00297 struct ast_category *category; 00298 00299 if ((category = ast_calloc(1, sizeof(*category)))) 00300 ast_copy_string(category->name, name, sizeof(category->name)); 00301 return category; 00302 }
void ast_category_rename | ( | struct ast_category * | cat, | |
const char * | name | |||
) |
struct ast_variable* ast_category_root | ( | struct ast_config * | config, | |
char * | cat | |||
) | [read] |
returns the root ast_variable of a config
config | pointer to an ast_config data structure | |
cat | name of the category for which you want the root |
Definition at line 356 of file config.c.
References ast_category_get(), and ast_category::root.
00357 { 00358 struct ast_category *category = ast_category_get(config, cat); 00359 if (category) 00360 return category->root; 00361 return NULL; 00362 }
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.
family | which family/config to be checked |
Definition at line 1334 of file config.c.
References find_engine().
01335 { 01336 struct ast_config_engine *eng; 01337 01338 eng = find_engine(family, NULL, 0, NULL, 0); 01339 if (eng) 01340 return 1; 01341 return 0; 01342 01343 }
void ast_config_destroy | ( | struct ast_config * | config | ) |
Destroys a config.
config | pointer to config data structure Free memory associated with a given config |
Definition at line 562 of file config.c.
References ast_variables_destroy(), free, ast_category::next, ast_category::root, and ast_config::root.
00563 { 00564 struct ast_category *cat, *catn; 00565 00566 if (!cfg) 00567 return; 00568 00569 cat = cfg->root; 00570 while(cat) { 00571 ast_variables_destroy(cat->root); 00572 catn = cat; 00573 cat = cat->next; 00574 free(catn); 00575 } 00576 free(cfg); 00577 }
int ast_config_engine_deregister | ( | struct ast_config_engine * | del | ) |
Deegister config engine.
Definition at line 1183 of file config.c.
References ast_mutex_lock(), ast_mutex_unlock(), last, and ast_config_engine::next.
01184 { 01185 struct ast_config_engine *ptr, *last=NULL; 01186 01187 ast_mutex_lock(&config_lock); 01188 01189 for (ptr = config_engine_list; ptr; ptr=ptr->next) { 01190 if (ptr == del) { 01191 if (last) 01192 last->next = ptr->next; 01193 else 01194 config_engine_list = ptr->next; 01195 break; 01196 } 01197 last = ptr; 01198 } 01199 01200 ast_mutex_unlock(&config_lock); 01201 01202 return 0; 01203 }
int ast_config_engine_register | ( | struct ast_config_engine * | newconfig | ) |
Register config engine.
Definition at line 1164 of file config.c.
References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), LOG_NOTICE, ast_config_engine::name, and ast_config_engine::next.
01165 { 01166 struct ast_config_engine *ptr; 01167 01168 ast_mutex_lock(&config_lock); 01169 01170 if (!config_engine_list) { 01171 config_engine_list = new; 01172 } else { 01173 for (ptr = config_engine_list; ptr->next; ptr=ptr->next); 01174 ptr->next = new; 01175 } 01176 01177 ast_mutex_unlock(&config_lock); 01178 ast_log(LOG_NOTICE,"Registered Config Engine %s\n", new->name); 01179 01180 return 1; 01181 }
struct ast_category* ast_config_get_current_category | ( | const struct ast_config * | cfg | ) | [read] |
Definition at line 579 of file config.c.
References ast_config::current.
00580 { 00581 return cfg->current; 00582 }
struct ast_config* ast_config_internal_load | ( | const char * | configfile, | |
struct ast_config * | cfg, | |||
int | withcomments | |||
) | [read] |
Definition at line 1245 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.
01246 { 01247 char db[256]; 01248 char table[256]; 01249 struct ast_config_engine *loader = &text_file_engine; 01250 struct ast_config *result; 01251 01252 if (cfg->include_level == cfg->max_include_level) { 01253 ast_log(LOG_WARNING, "Maximum Include level (%d) exceeded\n", cfg->max_include_level); 01254 return NULL; 01255 } 01256 01257 cfg->include_level++; 01258 01259 if (strcmp(filename, extconfig_conf) && strcmp(filename, "asterisk.conf") && config_engine_list) { 01260 struct ast_config_engine *eng; 01261 01262 eng = find_engine(filename, db, sizeof(db), table, sizeof(table)); 01263 01264 01265 if (eng && eng->load_func) { 01266 loader = eng; 01267 } else { 01268 eng = find_engine("global", db, sizeof(db), table, sizeof(table)); 01269 if (eng && eng->load_func) 01270 loader = eng; 01271 } 01272 } 01273 01274 result = loader->load_func(db, table, filename, cfg, withcomments); 01275 01276 if (result) 01277 result->include_level--; 01278 else 01279 cfg->include_level--; 01280 01281 return result; 01282 }
struct ast_config* ast_config_load | ( | const char * | filename | ) | [read] |
Load a config file.
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. |
Definition at line 1284 of file config.c.
References ast_config_destroy(), ast_config_internal_load(), and ast_config_new().
01285 { 01286 struct ast_config *cfg; 01287 struct ast_config *result; 01288 01289 cfg = ast_config_new(); 01290 if (!cfg) 01291 return NULL; 01292 01293 result = ast_config_internal_load(filename, cfg, 0); 01294 if (!result) 01295 ast_config_destroy(cfg); 01296 01297 return result; 01298 }
struct ast_config* ast_config_load_with_comments | ( | const char * | filename | ) | [read] |
Definition at line 1300 of file config.c.
References ast_config_destroy(), ast_config_internal_load(), and ast_config_new().
01301 { 01302 struct ast_config *cfg; 01303 struct ast_config *result; 01304 01305 cfg = ast_config_new(); 01306 if (!cfg) 01307 return NULL; 01308 01309 result = ast_config_internal_load(filename, cfg, 1); 01310 if (!result) 01311 ast_config_destroy(cfg); 01312 01313 return result; 01314 }
struct ast_config* ast_config_new | ( | void | ) | [read] |
Definition at line 420 of file config.c.
References ast_calloc, config, MAX_INCLUDE_LEVEL, and ast_config::max_include_level.
00421 { 00422 struct ast_config *config; 00423 00424 if ((config = ast_calloc(1, sizeof(*config)))) 00425 config->max_include_level = MAX_INCLUDE_LEVEL; 00426 return config; 00427 }
const char* ast_config_option | ( | struct ast_config * | cfg, | |
const char * | cat, | |||
const char * | var | |||
) |
Definition at line 233 of file config.c.
References ast_variable_retrieve().
00234 { 00235 const char *tmp; 00236 tmp = ast_variable_retrieve(cfg, cat, var); 00237 if (!tmp) 00238 tmp = ast_variable_retrieve(cfg, "general", var); 00239 return tmp; 00240 }
void ast_config_set_current_category | ( | struct ast_config * | cfg, | |
const struct ast_category * | cat | |||
) |
Definition at line 584 of file config.c.
References ast_config::current.
00585 { 00586 /* cast below is just to silence compiler warning about dropping "const" */ 00587 cfg->current = (struct ast_category *) cat; 00588 }
struct ast_variable* ast_load_realtime | ( | const char * | family, | |
... | ||||
) | [read] |
Retrieve realtime configuration.
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 1316 of file config.c.
References db, find_engine(), ast_config_engine::realtime_func, and table.
01317 { 01318 struct ast_config_engine *eng; 01319 char db[256]=""; 01320 char table[256]=""; 01321 struct ast_variable *res=NULL; 01322 va_list ap; 01323 01324 va_start(ap, family); 01325 eng = find_engine(family, db, sizeof(db), table, sizeof(table)); 01326 if (eng && eng->realtime_func) 01327 res = eng->realtime_func(db, table, ap); 01328 va_end(ap); 01329 01330 return res; 01331 }
struct ast_config* ast_load_realtime_multientry | ( | const char * | family, | |
... | ||||
) | [read] |
Retrieve realtime configuration.
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 1345 of file config.c.
References db, find_engine(), ast_config_engine::realtime_multi_func, and table.
01346 { 01347 struct ast_config_engine *eng; 01348 char db[256]=""; 01349 char table[256]=""; 01350 struct ast_config *res=NULL; 01351 va_list ap; 01352 01353 va_start(ap, family); 01354 eng = find_engine(family, db, sizeof(db), table, sizeof(table)); 01355 if (eng && eng->realtime_multi_func) 01356 res = eng->realtime_multi_func(db, table, ap); 01357 va_end(ap); 01358 01359 return res; 01360 }
int ast_update_realtime | ( | const char * | family, | |
const char * | keyfield, | |||
const char * | lookup, | |||
... | ||||
) |
Update realtime configuration.
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 1362 of file config.c.
References db, find_engine(), table, and ast_config_engine::update_func.
01363 { 01364 struct ast_config_engine *eng; 01365 int res = -1; 01366 char db[256]=""; 01367 char table[256]=""; 01368 va_list ap; 01369 01370 va_start(ap, lookup); 01371 eng = find_engine(family, db, sizeof(db), table, sizeof(table)); 01372 if (eng && eng->update_func) 01373 res = eng->update_func(db, table, keyfield, lookup, ap); 01374 va_end(ap); 01375 01376 return res; 01377 }
void ast_variable_append | ( | struct ast_category * | category, | |
struct ast_variable * | variable | |||
) |
Definition at line 197 of file config.c.
References ast_category::last, ast_variable::next, and ast_category::root.
00198 { 00199 if (!variable) 00200 return; 00201 if (category->last) 00202 category->last->next = variable; 00203 else 00204 category->root = variable; 00205 category->last = variable; 00206 while (category->last->next) 00207 category->last = category->last->next; 00208 }
struct ast_variable* ast_variable_browse | ( | const struct ast_config * | config, | |
const char * | category | |||
) | [read] |
Goes through variables Somewhat similar in intent as the ast_category_browse. List variables of config file category.
Returns ast_variable list on success, or NULL on failure
Definition at line 221 of file config.c.
References ast_category_get(), ast_config::last_browse, ast_category::name, and ast_category::root.
00222 { 00223 struct ast_category *cat = NULL; 00224 00225 if (category && config->last_browse && (config->last_browse->name == category)) 00226 cat = config->last_browse; 00227 else 00228 cat = ast_category_get(config, category); 00229 00230 return (cat) ? cat->root : NULL; 00231 }
int ast_variable_delete | ( | struct ast_category * | category, | |
char * | variable, | |||
char * | match | |||
) |
Definition at line 429 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.
00430 { 00431 struct ast_variable *cur, *prev=NULL, *curn; 00432 int res = -1; 00433 cur = category->root; 00434 while (cur) { 00435 if (cur->name == variable) { 00436 if (prev) { 00437 prev->next = cur->next; 00438 if (cur == category->last) 00439 category->last = prev; 00440 } else { 00441 category->root = cur->next; 00442 if (cur == category->last) 00443 category->last = NULL; 00444 } 00445 cur->next = NULL; 00446 ast_variables_destroy(cur); 00447 return 0; 00448 } 00449 prev = cur; 00450 cur = cur->next; 00451 } 00452 00453 prev = NULL; 00454 cur = category->root; 00455 while (cur) { 00456 curn = cur->next; 00457 if (!strcasecmp(cur->name, variable) && (ast_strlen_zero(match) || !strcasecmp(cur->value, match))) { 00458 if (prev) { 00459 prev->next = cur->next; 00460 if (cur == category->last) 00461 category->last = prev; 00462 } else { 00463 category->root = cur->next; 00464 if (cur == category->last) 00465 category->last = NULL; 00466 } 00467 cur->next = NULL; 00468 ast_variables_destroy(cur); 00469 res = 0; 00470 } else 00471 prev = cur; 00472 00473 cur = curn; 00474 } 00475 return res; 00476 }
struct ast_variable* ast_variable_new | ( | const char * | name, | |
const char * | value | |||
) | [read] |
Definition at line 182 of file config.c.
References ast_calloc, ast_variable::name, ast_variable::stuff, and ast_variable::value.
00183 { 00184 struct ast_variable *variable; 00185 int name_len = strlen(name) + 1; 00186 00187 if ((variable = ast_calloc(1, name_len + strlen(value) + 1 + sizeof(*variable)))) { 00188 variable->name = variable->stuff; 00189 variable->value = variable->stuff + name_len; 00190 strcpy(variable->name,name); 00191 strcpy(variable->value,value); 00192 } 00193 00194 return variable; 00195 }
const char* ast_variable_retrieve | ( | const struct ast_config * | config, | |
const char * | category, | |||
const char * | variable | |||
) |
Gets a variable.
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 |
Definition at line 243 of file config.c.
References ast_variable_browse(), ast_variable::name, ast_category::next, ast_variable::next, ast_category::root, ast_config::root, and ast_variable::value.
00244 { 00245 struct ast_variable *v; 00246 00247 if (category) { 00248 for (v = ast_variable_browse(config, category); v; v = v->next) { 00249 if (!strcasecmp(variable, v->name)) 00250 return v->value; 00251 } 00252 } else { 00253 struct ast_category *cat; 00254 00255 for (cat = config->root; cat; cat = cat->next) 00256 for (v = cat->root; v; v = v->next) 00257 if (!strcasecmp(variable, v->name)) 00258 return v->value; 00259 } 00260 00261 return NULL; 00262 }
int ast_variable_update | ( | struct ast_category * | category, | |
const char * | variable, | |||
const char * | value, | |||
const char * | match, | |||
unsigned int | object | |||
) |
Definition at line 478 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.
00480 { 00481 struct ast_variable *cur, *prev=NULL, *newer; 00482 00483 if (!(newer = ast_variable_new(variable, value))) 00484 return -1; 00485 00486 newer->object = object; 00487 00488 for (cur = category->root; cur; prev = cur, cur = cur->next) { 00489 if (strcasecmp(cur->name, variable) || 00490 (!ast_strlen_zero(match) && strcasecmp(cur->value, match))) 00491 continue; 00492 00493 newer->next = cur->next; 00494 newer->object = cur->object || object; 00495 if (prev) 00496 prev->next = newer; 00497 else 00498 category->root = newer; 00499 if (category->last == cur) 00500 category->last = newer; 00501 00502 cur->next = NULL; 00503 ast_variables_destroy(cur); 00504 00505 return 0; 00506 } 00507 00508 if (prev) 00509 prev->next = newer; 00510 else 00511 category->root = newer; 00512 00513 return 0; 00514 }
void ast_variables_destroy | ( | struct ast_variable * | var | ) |
Free variable list.
var | the linked list of variables to free This function frees a list of variables. |
Definition at line 210 of file config.c.
References free, and ast_variable::next.
00211 { 00212 struct ast_variable *vn; 00213 00214 while(v) { 00215 vn = v; 00216 v = v->next; 00217 free(vn); 00218 } 00219 }
int config_text_file_save | ( | const char * | filename, | |
const struct ast_config * | cfg, | |||
const char * | generator | |||
) |
Definition at line 957 of file config.c.
References ast_config_AST_CONFIG_DIR, ast_log(), ast_verbose(), ast_variable::blanklines, ast_comment::cmt, f, LOG_DEBUG, ast_variable::name, ast_category::name, ast_category::next, ast_variable::next, ast_comment::next, ast_variable::object, option_debug, option_verbose, ast_variable::precomments, ast_category::precomments, ast_category::root, ast_config::root, ast_variable::sameline, ast_category::sameline, t, ast_variable::value, var, and VERBOSE_PREFIX_2.
00958 { 00959 FILE *f; 00960 char fn[256]; 00961 char date[256]=""; 00962 time_t t; 00963 struct ast_variable *var; 00964 struct ast_category *cat; 00965 struct ast_comment *cmt; 00966 int blanklines = 0; 00967 00968 if (configfile[0] == '/') { 00969 ast_copy_string(fn, configfile, sizeof(fn)); 00970 } else { 00971 snprintf(fn, sizeof(fn), "%s/%s", ast_config_AST_CONFIG_DIR, configfile); 00972 } 00973 time(&t); 00974 ast_copy_string(date, ctime(&t), sizeof(date)); 00975 #ifdef __CYGWIN__ 00976 if ((f = fopen(fn, "w+"))) { 00977 #else 00978 if ((f = fopen(fn, "w"))) { 00979 #endif 00980 if (option_verbose > 1) 00981 ast_verbose(VERBOSE_PREFIX_2 "Saving '%s': ", fn); 00982 fprintf(f, ";!\n"); 00983 fprintf(f, ";! Automatically generated configuration file\n"); 00984 if (strcmp(configfile, fn)) 00985 fprintf(f, ";! Filename: %s (%s)\n", configfile, fn); 00986 else 00987 fprintf(f, ";! Filename: %s\n", configfile); 00988 fprintf(f, ";! Generator: %s\n", generator); 00989 fprintf(f, ";! Creation Date: %s", date); 00990 fprintf(f, ";!\n"); 00991 cat = cfg->root; 00992 while(cat) { 00993 /* Dump section with any appropriate comment */ 00994 for (cmt = cat->precomments; cmt; cmt=cmt->next) 00995 { 00996 if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!') 00997 fprintf(f,"%s", cmt->cmt); 00998 } 00999 if (!cat->precomments) 01000 fprintf(f,"\n"); 01001 fprintf(f, "[%s]", cat->name); 01002 for(cmt = cat->sameline; cmt; cmt=cmt->next) 01003 { 01004 fprintf(f,"%s", cmt->cmt); 01005 } 01006 if (!cat->sameline) 01007 fprintf(f,"\n"); 01008 var = cat->root; 01009 while(var) { 01010 for (cmt = var->precomments; cmt; cmt=cmt->next) 01011 { 01012 if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!') 01013 fprintf(f,"%s", cmt->cmt); 01014 } 01015 if (var->sameline) 01016 fprintf(f, "%s %s %s %s", var->name, (var->object ? "=>" : "="), var->value, var->sameline->cmt); 01017 else 01018 fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="), var->value); 01019 if (var->blanklines) { 01020 blanklines = var->blanklines; 01021 while (blanklines--) 01022 fprintf(f, "\n"); 01023 } 01024 01025 var = var->next; 01026 } 01027 #if 0 01028 /* Put an empty line */ 01029 fprintf(f, "\n"); 01030 #endif 01031 cat = cat->next; 01032 } 01033 if ((option_verbose > 1) && !option_debug) 01034 ast_verbose("Saved\n"); 01035 } else { 01036 if (option_debug) 01037 ast_log(LOG_DEBUG, "Unable to open for writing: %s\n", fn); 01038 if (option_verbose > 1) 01039 ast_verbose(VERBOSE_PREFIX_2 "Unable to write (%s)", strerror(errno)); 01040 return -1; 01041 } 01042 fclose(f); 01043 return 0; 01044 }
int read_config_maps | ( | void | ) |
Definition at line 1096 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.
01097 { 01098 struct ast_config *config, *configtmp; 01099 struct ast_variable *v; 01100 char *driver, *table, *database, *stringp, *tmp; 01101 01102 clear_config_maps(); 01103 01104 configtmp = ast_config_new(); 01105 configtmp->max_include_level = 1; 01106 config = ast_config_internal_load(extconfig_conf, configtmp, 0); 01107 if (!config) { 01108 ast_config_destroy(configtmp); 01109 return 0; 01110 } 01111 01112 for (v = ast_variable_browse(config, "settings"); v; v = v->next) { 01113 stringp = v->value; 01114 driver = strsep(&stringp, ","); 01115 01116 if ((tmp = strchr(stringp, '\"'))) 01117 stringp = tmp; 01118 01119 /* check if the database text starts with a double quote */ 01120 if (*stringp == '"') { 01121 stringp++; 01122 database = strsep(&stringp, "\""); 01123 strsep(&stringp, ","); 01124 } else { 01125 /* apparently this text has no quotes */ 01126 database = strsep(&stringp, ","); 01127 } 01128 01129 table = strsep(&stringp, ","); 01130 01131 if (!strcmp(v->name, extconfig_conf)) { 01132 ast_log(LOG_WARNING, "Cannot bind '%s'!\n", extconfig_conf); 01133 continue; 01134 } 01135 01136 if (!strcmp(v->name, "asterisk.conf")) { 01137 ast_log(LOG_WARNING, "Cannot bind 'asterisk.conf'!\n"); 01138 continue; 01139 } 01140 01141 if (!strcmp(v->name, "logger.conf")) { 01142 ast_log(LOG_WARNING, "Cannot bind 'logger.conf'!\n"); 01143 continue; 01144 } 01145 01146 if (!driver || !database) 01147 continue; 01148 if (!strcasecmp(v->name, "sipfriends")) { 01149 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"); 01150 append_mapping("sipusers", driver, database, table ? table : "sipfriends"); 01151 append_mapping("sippeers", driver, database, table ? table : "sipfriends"); 01152 } else if (!strcasecmp(v->name, "iaxfriends")) { 01153 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"); 01154 append_mapping("iaxusers", driver, database, table ? table : "iaxfriends"); 01155 append_mapping("iaxpeers", driver, database, table ? table : "iaxfriends"); 01156 } else 01157 append_mapping(v->name, driver, database, table); 01158 } 01159 01160 ast_config_destroy(config); 01161 return 0; 01162 }
int register_config_cli | ( | void | ) |
Definition at line 1417 of file config.c.
References ast_cli_register_multiple().
01418 { 01419 ast_cli_register_multiple(cli_config, sizeof(cli_config) / sizeof(struct ast_cli_entry)); 01420 return 0; 01421 }