![]() |
Home page |
Mailing list |
Docs
Asterisk developer's documentation :: Codename Pineapple
config.c File Reference
Definition in file config.c.
#include "asterisk.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <sys/stat.h>
#include <glob.h>
#include "asterisk/config.h"
#include "asterisk/cli.h"
#include "asterisk/lock.h"
#include "asterisk/options.h"
#include "asterisk/logger.h"
#include "asterisk/utils.h"
#include "asterisk/channel.h"
#include "asterisk/app.h"
Include dependency graph for config.c:

Go to the source code of this file.
Data Structures | |
| struct | ast_category |
| struct | ast_comment |
| struct | ast_config |
| struct | ast_config_map |
Defines | |
| #define | AST_INCLUDE_GLOB 1 |
| #define | CB_INCR 250 |
| #define | COMMENT_END "--;" |
| #define | COMMENT_META ';' |
| #define | COMMENT_START ";--" |
| #define | COMMENT_TAG '-' |
| #define | MAX_INCLUDE_LEVEL 10 |
| #define | MAX_NESTED_COMMENTS 128 |
Functions | |
| static struct ast_comment * | ALLOC_COMMENT (const char *buffer) |
| static int | append_mapping (char *name, char *driver, char *database, char *table) |
| void | ast_category_append (struct ast_config *config, struct ast_category *category) |
| 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_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. | |
| ast_category * | ast_category_get (const struct ast_config *config, const char *category_name) |
| Retrieve a category if it exists. | |
| ast_category * | ast_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 *cfg) |
| 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 *new) |
| Register config engine. | |
| ast_category * | ast_config_get_current_category (const struct ast_config *cfg) |
| ast_config * | ast_config_internal_load (const char *filename, struct ast_config *cfg, int withcomments) |
| ast_config * | ast_config_load (const char *filename) |
| Load a config file. | |
| ast_config * | ast_config_load_with_comments (const char *filename) |
| 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) |
| ast_variable * | ast_load_realtime (const char *family,...) |
| Retrieve realtime configuration. | |
| ast_variable * | ast_load_realtime_all (const char *family,...) |
| static struct ast_variable * | ast_load_realtime_helper (const char *family, va_list ap) |
| ast_config * | ast_load_realtime_multientry (const char *family,...) |
| Retrieve realtime configuration. | |
| AST_MUTEX_DEFINE_STATIC (config_lock) | |
| 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_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, const char *variable, const char *match) |
| 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) |
| void | ast_variables_destroy (struct ast_variable *v) |
| Free variable list. | |
| static struct ast_category * | category_get (const struct ast_config *config, const char *category_name, int ignored) |
| static void | CB_ADD (char *str) |
| static void | CB_ADD_LEN (char *str, int len) |
| static void | CB_INIT (void) |
| static void | CB_RESET (void) |
| static void | clear_config_maps (void) |
| static int | config_command (int fd, int argc, char **argv) |
| static struct ast_config * | config_text_file_load (const char *database, const char *table, const char *filename, struct ast_config *cfg, int withcomments) |
| int | config_text_file_save (const char *configfile, const struct ast_config *cfg, const char *generator) |
| static struct ast_config_engine * | find_engine (const char *family, char *database, int dbsiz, char *table, int tabsiz) |
| Find realtime engine for realtime family. | |
| static void | inherit_category (struct ast_category *new, const struct ast_category *base) |
| static void | LLB_ADD (char *str) |
| static void | move_variables (struct ast_category *old, struct ast_category *new) |
| static struct ast_category * | next_available_category (struct ast_category *cat) |
| static int | process_text_line (struct ast_config *cfg, struct ast_category **cat, char *buf, int lineno, const char *configfile, int withcomments) |
| int | read_config_maps (void) |
| int | register_config_cli () |
| static struct ast_variable * | variable_clone (const struct ast_variable *old) |
Variables | |
| static struct ast_cli_entry | cli_config [] |
| static char * | comment_buffer |
| static int | comment_buffer_size |
| static struct ast_config_engine * | config_engine_list |
| static struct ast_config_map * | config_maps |
| static char * | extconfig_conf = "extconfig.conf" |
| static char * | lline_buffer |
| static int | lline_buffer_size |
| static char | show_config_help [] |
| static struct ast_config_engine | text_file_engine |
|
|
|
|
|
Definition at line 78 of file config.c. Referenced by CB_ADD(), CB_ADD_LEN(), CB_INIT(), and LLB_ADD(). |
|
|
|
|
|
Definition at line 60 of file config.c. Referenced by config_text_file_load(). |
|
|
|
|
|
Definition at line 61 of file config.c. Referenced by config_text_file_load(). |
|
|
Definition at line 167 of file config.c. Referenced by ast_config_new(). |
|
|
Definition at line 57 of file config.c. Referenced by config_text_file_load(). |
|
|
Definition at line 147 of file config.c. References ast_calloc, and ast_comment::cmt. Referenced by process_text_line(). 00148 { 00149 struct ast_comment *x = ast_calloc(1,sizeof(struct ast_comment)+strlen(buffer)+1); 00150 strcpy(x->cmt, buffer); 00151 return x; 00152 }
|
|
||||||||||||||||||||
|
Definition at line 1067 of file config.c. References ast_calloc, ast_verbose(), config_maps, map, option_verbose, and VERBOSE_PREFIX_2. 01068 { 01069 struct ast_config_map *map; 01070 int length; 01071 01072 length = sizeof(*map); 01073 length += strlen(name) + 1; 01074 length += strlen(driver) + 1; 01075 length += strlen(database) + 1; 01076 if (table) 01077 length += strlen(table) + 1; 01078 01079 if (!(map = ast_calloc(1, length))) 01080 return -1; 01081 01082 map->name = map->stuff; 01083 strcpy(map->name, name); 01084 map->driver = map->name + strlen(map->name) + 1; 01085 strcpy(map->driver, driver); 01086 map->database = map->driver + strlen(map->driver) + 1; 01087 strcpy(map->database, database); 01088 if (table) { 01089 map->table = map->database + strlen(map->database) + 1; 01090 strcpy(map->table, table); 01091 } 01092 map->next = config_maps; 01093 01094 if (option_verbose > 1) 01095 ast_verbose(VERBOSE_PREFIX_2 "Binding %s to %s/%s/%s\n", 01096 map->name, map->driver, map->database, map->table ? map->table : map->name); 01097 01098 config_maps = map; 01099 return 0; 01100 }
|
|
||||||||||||
|
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 }
|
|
||||||||||||
|
Goes through 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 }
|
|
||||||||||||
|
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 }
|
|
|
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 }
|
|
|
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 }
|
|
||||||||||||
|
Check for category duplicates.
Definition at line 334 of file config.c. References ast_category_get(), and config. 00335 { 00336 return !!ast_category_get(config, category_name); 00337 }
|
|
||||||||||||
|
Retrieve a category if it exists.
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 }
|
|
|
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 }
|
|
||||||||||||
|
Definition at line 406 of file config.c. References ast_category::name. Referenced by handle_updates(), realtime_multi_odbc(), and realtime_multi_pgsql().
|
|
|
Check if realtime engine is configured for family returns 1 if family is configured in realtime and engine exists.
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 }
|
|
|
Destroys a config.
Definition at line 574 of file config.c. References ast_variables_destroy(), free, ast_category::next, ast_config::root, and ast_category::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 }
|
|
|
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 }
|
|
|
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 }
|
|
|
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 }
|
|
||||||||||||||||
|
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 }
|
|
|
|
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 }
|
|
|
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 }
|
|
||||||||||||||||
|
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 }
|
|
||||||||||||
|
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 }
|
|
||||||||||||
|
Retrieve realtime configuration.
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 }
|
|
||||||||||||
|
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 }
|
|
||||||||||||
|
Definition at line 1320 of file config.c. References find_engine(), and ast_config_engine::realtime_func. Referenced by ast_load_realtime(), and ast_load_realtime_all(). 01321 { 01322 struct ast_config_engine *eng; 01323 char db[256]=""; 01324 char table[256]=""; 01325 struct ast_variable *res=NULL; 01326 01327 eng = find_engine(family, db, sizeof(db), table, sizeof(table)); 01328 if (eng && eng->realtime_func) 01329 res = eng->realtime_func(db, table, ap); 01330 01331 return res; 01332 }
|
|
||||||||||||
|
Retrieve realtime configuration.
Definition at line 1387 of file config.c. References find_engine(), and ast_config_engine::realtime_multi_func. Referenced by realtime_s |