Thu May 14 15:13:30 2009

Asterisk developer's documentation


config.c File Reference

Configuration File Parser. More...

#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"

Go to the source code of this file.

Data Structures

struct  ast_category
struct  ast_category::template_instance_list
struct  ast_category_template_instance
struct  ast_comment
 Structure to keep comments for rewriting configuration files. More...
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_commentALLOC_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, 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)
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 *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_categoryast_config_get_current_category (const struct ast_config *cfg)
ast_configast_config_internal_load (const char *filename, 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)
static void ast_destroy_comments (struct ast_category *cat)
static void ast_destroy_template_list (struct ast_category *cat)
ast_variableast_load_realtime (const char *family,...)
 Retrieve realtime configuration.
ast_configast_load_realtime_multientry (const char *family,...)
 Retrieve realtime configuration.
int ast_realtime_enabled (void)
 Check if realtime engine is enabled returns 1 if realtime is enabled.
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, char *variable, char *match)
ast_variableast_variable_new (const char *name, const char *value)
ast_variableast_variable_next (struct ast_config *config, char *category, struct ast_variable *prev)
 Iterates through variables.
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 *v)
 Free variable list.
static struct ast_categorycategory_get (const struct ast_config *config, const char *category_name, int ignored)
static void CB_ADD (char **comment_buffer, int *comment_buffer_size, char *str)
static void CB_ADD_LEN (char **comment_buffer, int *comment_buffer_size, char *str, int len)
static void CB_INIT (char **comment_buffer, int *comment_buffer_size, char **lline_buffer, int *lline_buffer_size)
static void CB_RESET (char **comment_buffer, char **lline_buffer)
static void clear_config_maps (void)
static int config_command (int fd, int argc, char **argv)
static struct ast_configconfig_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_enginefind_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 **lline_buffer, int *lline_buffer_size, char *str)
static void move_variables (struct ast_category *old, struct ast_category *new)
static struct ast_categorynext_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, char **comment_buffer, int *comment_buffer_size, char **lline_buffer, int *lline_buffer_size)
int read_config_maps (void)
int register_config_cli ()
static struct ast_variablevariable_clone (const struct ast_variable *old)

Variables

static struct ast_cli_entry cli_config []
static struct ast_cli_entry cli_show_config_mappings_deprecated
static struct ast_config_engineconfig_engine_list
static ast_mutex_t config_lock = ((ast_mutex_t) PTHREAD_MUTEX_INITIALIZER )
static struct ast_config_mapconfig_maps
static char * extconfig_conf = "extconfig.conf"
static char show_config_help []
static struct ast_config_engine text_file_engine


Detailed Description

Configuration File Parser.

Author:
Mark Spencer <markster@digium.com>
Includes the Asterisk Realtime API - ARA See doc/realtime.txt and doc/extconfig.txt

Definition in file config.c.


Define Documentation

#define AST_INCLUDE_GLOB   1

Definition at line 40 of file config.c.

#define CB_INCR   250

Definition at line 72 of file config.c.

Referenced by CB_ADD(), CB_ADD_LEN(), CB_INIT(), and LLB_ADD().

#define COMMENT_END   "--;"

Definition at line 59 of file config.c.

#define COMMENT_META   ';'

Definition at line 60 of file config.c.

Referenced by config_text_file_load().

#define COMMENT_START   ";--"

Definition at line 58 of file config.c.

#define COMMENT_TAG   '-'

Definition at line 61 of file config.c.

Referenced by config_text_file_load().

#define MAX_INCLUDE_LEVEL   10

Definition at line 160 of file config.c.

Referenced by ast_config_new().

#define MAX_NESTED_COMMENTS   128

Definition at line 57 of file config.c.

Referenced by config_text_file_load().


Function Documentation

static struct ast_comment* ALLOC_COMMENT ( const char *  buffer  )  [static]

Definition at line 140 of file config.c.

References ast_calloc, and ast_comment::cmt.

Referenced by process_text_line().

00141 { 
00142    struct ast_comment *x = ast_calloc(1,sizeof(struct ast_comment)+strlen(buffer)+1);
00143    strcpy(x->cmt, buffer);
00144    return x;
00145 }

static int append_mapping ( char *  name,
char *  driver,
char *  database,
char *  table 
) [static]

Definition at line 1178 of file config.c.

References ast_calloc, ast_verbose(), config_maps, map, option_verbose, and VERBOSE_PREFIX_2.

Referenced by read_config_maps().

01179 {
01180    struct ast_config_map *map;
01181    int length;
01182 
01183    length = sizeof(*map);
01184    length += strlen(name) + 1;
01185    length += strlen(driver) + 1;
01186    length += strlen(database) + 1;
01187    if (table)
01188       length += strlen(table) + 1;
01189 
01190    if (!(map = ast_calloc(1, length)))
01191       return -1;
01192 
01193    map->name = map->stuff;
01194    strcpy(map->name, name);
01195    map->driver = map->name + strlen(map->name) + 1;
01196    strcpy(map->driver, driver);
01197    map->database = map->driver + strlen(map->driver) + 1;
01198    strcpy(map->database, database);
01199    if (table) {
01200       map->table = map->database + strlen(map->database) + 1;
01201       strcpy(map->table, table);
01202    }
01203    map->next = config_maps;
01204 
01205    if (option_verbose > 1)
01206       ast_verbose(VERBOSE_PREFIX_2 "Binding %s to %s/%s/%s\n",
01207              map->name, map->driver, map->database, map->table ? map->table : map->name);
01208 
01209    config_maps = map;
01210    return 0;
01211 }

void ast_category_append ( struct ast_config config,
struct ast_category category 
)

Definition at line 358 of file config.c.

References config, and ast_category::include_level.

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

00359 {
00360    if (config->last)
00361       config->last->next = category;
00362    else
00363       config->root = category;
00364    category->include_level = config->include_level;
00365    config->last = category;
00366    config->current = category;
00367 }

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

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

Referenced by __queues_show(), action_getconfig(), aji_load_config(), authenticate(), complete_sipnotify(), do_directory(), 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_switch_common(), reload(), reload_config(), reload_followme(), reload_queues(), rpt_master(), set_config(), setup_dahdi(), sla_load_config(), update_realtime_members(), and vm_change_password().

00418 {  
00419    struct ast_category *cat = NULL;
00420 
00421    if (prev && config->last_browse && (config->last_browse->name == prev))
00422       cat = config->last_browse->next;
00423    else if (!prev && config->root)
00424       cat = config->root;
00425    else if (prev) {
00426       for (cat = config->root; cat; cat = cat->next) {
00427          if (cat->name == prev) {
00428             cat = cat->next;
00429             break;
00430          }
00431       }
00432       if (!cat) {
00433          for (cat = config->root; cat; cat = cat->next) {
00434             if (!strcasecmp(cat->name, prev)) {
00435                cat = cat->next;
00436                break;
00437             }
00438          }
00439       }
00440    }
00441    
00442    if (cat)
00443       cat = next_available_category(cat);
00444 
00445    config->last_browse = cat;
00446    return (cat) ? cat->name : NULL;
00447 }

int ast_category_delete ( struct ast_config cfg,
char *  category 
)

Definition at line 572 of file config.c.

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

Referenced by handle_updates().

00573 {
00574    struct ast_category *prev=NULL, *cat;
00575    cat = cfg->root;
00576    while(cat) {
00577       if (cat->name == category) {
00578          if (prev) {
00579             prev->next = cat->next;
00580             if (cat == cfg->last)
00581                cfg->last = prev;
00582          } else {
00583             cfg->root = cat->next;
00584             if (cat == cfg->last)
00585                cfg->last = NULL;
00586          }
00587          ast_category_destroy(cat);
00588          return 0;
00589       }
00590       prev = cat;
00591       cat = cat->next;
00592    }
00593 
00594    prev = NULL;
00595    cat = cfg->root;
00596    while(cat) {
00597       if (!strcasecmp(cat->name, category)) {
00598          if (prev) {
00599             prev->next = cat->next;
00600             if (cat == cfg->last)
00601                cfg->last = prev;
00602          } else {
00603             cfg->root = cat->next;
00604             if (cat == cfg->last)
00605                cfg->last = NULL;
00606          }
00607          ast_category_destroy(cat);
00608          return 0;
00609       }
00610       prev = cat;
00611       cat = cat->next;
00612    }
00613    return -1;
00614 }

void ast_category_destroy ( struct ast_category cat  ) 

Definition at line 394 of file config.c.

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

Referenced by ast_category_delete(), ast_config_destroy(), process_text_line(), and realtime_multi_odbc().

00395 {
00396    ast_variables_destroy(cat->root);
00397    ast_destroy_comments(cat);
00398    ast_destroy_template_list(cat);
00399    free(cat);
00400 }

struct ast_variable* ast_category_detach_variables ( struct ast_category cat  ) 

Definition at line 449 of file config.c.

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

Referenced by realtime_switch_common().

00450 {
00451    struct ast_variable *v;
00452 
00453    v = cat->root;
00454    cat->root = NULL;
00455    cat->last = NULL;
00456 
00457    return v;
00458 }

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

References ast_category_get(), and config.

00354 {
00355    return !!ast_category_get(config, category_name);
00356 }

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

References category_get(), and config.

Referenced by ast_category_exist(), ast_category_root(), ast_variable_browse(), handle_updates(), realtime_directory(), realtime_switch_common(), vm_change_password(), and vm_forwardoptions().

00349 {
00350    return category_get(config, category_name, 0);
00351 }

struct ast_category* ast_category_new ( const char *  name  ) 

Definition at line 321 of file config.c.

References ast_calloc, and ast_copy_string().

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

00322 {
00323    struct ast_category *category;
00324 
00325    if ((category = ast_calloc(1, sizeof(*category))))
00326       ast_copy_string(category->name, name, sizeof(category->name));
00327    return category;
00328 }

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

Definition at line 460 of file config.c.

References ast_copy_string(), and ast_category::name.

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

00461 {
00462    ast_copy_string(cat->name, name, sizeof(cat->name));
00463 }

struct ast_variable* ast_category_root ( struct ast_config config,
char *  cat 
)

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

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

00410 {
00411    struct ast_category *category = ast_category_get(config, cat);
00412    if (category)
00413       return category->root;
00414    return NULL;
00415 }

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

References find_engine().

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

01453 {
01454    struct ast_config_engine *eng;
01455 
01456    eng = find_engine(family, NULL, 0, NULL, 0);
01457    if (eng)
01458       return 1;
01459    return 0;
01460 
01461 }

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

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

Referenced by __ast_http_load(), __queues_show(), action_getconfig(), action_updateconfig(), adsi_load(), advanced_options(), aji_load_config(), ast_config_load(), ast_config_load_with_comments(), ast_enum_init(), 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(), load_config(), load_config_meetme(), load_module(), load_realtime_queue(), load_rpt_vars(), loadconfigurationfile(), my_load_module(), node_lookup(), odbc_load_module(), osp_load(), parse_config(), pbx_load_users(), play_message(), privacy_exec(), read_agent_config(), read_config_maps(), realtime_directory(), realtime_switch_common(), reload(), reload_config(), reload_followme(), rpt_master(), set_config(), setup_dahdi(), sla_load_config(), tds_load_module(), unload_module(), update_realtime_members(), and vm_forwardoptions().

00617 {
00618    struct ast_category *cat, *catn;
00619 
00620    if (!cfg)
00621       return;
00622 
00623    cat = cfg->root;
00624    while(cat) {
00625       catn = cat;
00626       cat = cat->next;
00627       ast_category_destroy(catn);
00628    }
00629    free(cfg);
00630 }

int ast_config_engine_deregister ( struct ast_config_engine del  ) 

Deegister config engine.

Definition at line 1300 of file config.c.

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

Referenced by unload_module().

01301 {
01302    struct ast_config_engine *ptr, *last=NULL;
01303 
01304    ast_mutex_lock(&config_lock);
01305 
01306    for (ptr = config_engine_list; ptr; ptr=ptr->next) {
01307       if (ptr == del) {
01308          if (last)
01309             last->next = ptr->next;
01310          else
01311             config_engine_list = ptr->next;
01312          break;
01313       }
01314       last = ptr;
01315    }
01316 
01317    ast_mutex_unlock(&config_lock);
01318 
01319    return 0;
01320 }

int ast_config_engine_register ( struct ast_config_engine new  ) 

Register config engine.

Definition at line 1281 of file config.c.

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

Referenced by load_module().

01282 {
01283    struct ast_config_engine *ptr;
01284 
01285    ast_mutex_lock(&config_lock);
01286 
01287    if (!config_engine_list) {
01288       config_engine_list = new;
01289    } else {
01290       for (ptr = config_engine_list; ptr->next; ptr=ptr->next);
01291       ptr->next = new;
01292    }
01293 
01294    ast_mutex_unlock(&config_lock);
01295    ast_log(LOG_NOTICE,"Registered Config Engine %s\n", new->name);
01296 
01297    return 1;
01298 }

struct ast_category* ast_config_get_current_category ( const struct ast_config cfg  ) 

Definition at line 632 of file config.c.

References ast_config::current.

Referenced by config_odbc(), and config_text_file_load().

00633 {
00634    return cfg->current;
00635 }

struct ast_config* ast_config_internal_load ( const char *  filename,
struct ast_config cfg,
int  withcomments 
)

Definition at line 1362 of file config.c.

References ast_log(), config_engine_list, db, find_engine(), ast_config::include_level, ast_config_engine::load_func, LOG_WARNING, ast_config::max_include_level, table, 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().

01363 {
01364    char db[256];
01365    char table[256];
01366    struct ast_config_engine *loader = &text_file_engine;
01367    struct ast_config *result; 
01368 
01369    /* The config file itself bumps include_level by 1 */
01370    if (cfg->max_include_level > 0 && cfg->include_level == cfg->max_include_level + 1) {
01371       ast_log(LOG_WARNING, "Maximum Include level (%d) exceeded\n", cfg->max_include_level);
01372       return NULL;
01373    }
01374 
01375    cfg->include_level++;
01376 
01377    if (strcmp(filename, extconfig_conf) && strcmp(filename, "asterisk.conf") && config_engine_list) {
01378       struct ast_config_engine *eng;
01379 
01380       eng = find_engine(filename, db, sizeof(db), table, sizeof(table));
01381 
01382 
01383       if (eng && eng->load_func) {
01384          loader = eng;
01385       } else {
01386          eng = find_engine("global", db, sizeof(db), table, sizeof(table));
01387          if (eng && eng->load_func)
01388             loader = eng;
01389       }
01390    }
01391 
01392    result = loader->load_func(db, table, filename, cfg, withcomments);
01393 
01394    if (result)
01395       result->include_level--;
01396    else
01397       cfg->include_level--;
01398 
01399    return result;
01400 }

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 1402 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_dahdi(), sla_load_config(), smdi_load(), tds_load_module(), and vm_forwardoptions().

01403 {
01404    struct ast_config *cfg;
01405    struct ast_config *result;
01406 
01407    cfg = ast_config_new();
01408    if (!cfg)
01409       return NULL;
01410 
01411    result = ast_config_internal_load(filename, cfg, 0);
01412    if (!result)
01413       ast_config_destroy(cfg);
01414 
01415    return result;
01416 }

struct ast_config* ast_config_load_with_comments ( const char *  filename  ) 

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

01419 {
01420    struct ast_config *cfg;
01421    struct ast_config *result;
01422 
01423    cfg = ast_config_new();
01424    if (!cfg)
01425       return NULL;
01426 
01427    result = ast_config_internal_load(filename, cfg, 1);
01428    if (!result)
01429       ast_config_destroy(cfg);
01430 
01431    return result;
01432 }

struct ast_config* ast_config_new ( void   ) 

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

00477 {
00478    struct ast_config *config;
00479 
00480    if ((config = ast_calloc(1, sizeof(*config))))
00481       config->max_include_level = MAX_INCLUDE_LEVEL;
00482    return config;
00483 }

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

References ast_config::current.

00638 {
00639    /* cast below is just to silence compiler warning about dropping "const" */
00640    cfg->current = (struct ast_category *) cat;
00641 }

static void ast_destroy_comments ( struct ast_category cat  )  [static]

Definition at line 369 of file config.c.

References free, ast_comment::next, ast_category::precomments, and ast_category::sameline.

Referenced by ast_category_destroy().

00370 {
00371    struct ast_comment *n, *p;
00372    for (p=cat->precomments; p; p=n) {
00373       n = p->next;
00374       free(p);
00375    }
00376    for (p=cat->sameline; p; p=n) {
00377       n = p->next;
00378       free(p);
00379    }
00380    cat->precomments = NULL;
00381    cat->sameline = NULL;
00382 }

static void ast_destroy_template_list ( struct ast_category cat  )  [static]

Definition at line 384 of file config.c.

References AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, free, ast_category_template_instance::next, and ast_category::template_instances.

Referenced by ast_category_destroy().

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 1434 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(), queue_function_queuewaitingcount(), realtime_alias(), realtime_exec(), realtime_peer(), realtime_switch_common(), realtime_user(), and update_realtime_member_field().

01435 {
01436    struct ast_config_engine *eng;
01437    char db[256]="";
01438    char table[256]="";
01439    struct ast_variable *res=NULL;
01440    va_list ap;
01441 
01442    va_start(ap, family);
01443    eng = find_engine(family, db, sizeof(db), table, sizeof(table));
01444    if (eng && eng->realtime_func) 
01445       res = eng->realtime_func(db, table, ap);
01446    va_end(ap);
01447 
01448    return res;
01449 }

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

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

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

01470 {
01471    struct ast_config_engine *eng;
01472    char db[256]="";
01473    char table[256]="";
01474    struct ast_config *res=NULL;
01475    va_list ap;
01476 
01477    va_start(ap, family);
01478    eng = find_engine(family, db, sizeof(db), table, sizeof(table));
01479    if (eng && eng->realtime_multi_func) 
01480       res = eng->realtime_multi_func(db, table, ap);
01481    va_end(ap);
01482 
01483    return res;
01484 }

int ast_realtime_enabled ( void   ) 

Check if realtime engine is enabled returns 1 if realtime is enabled.

Definition at line 1464 of file config.c.

References config_maps.

Referenced by action_coresettings(), and handle_show_settings().

01465 {
01466    return config_maps ? 1 : 0;
01467 }

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.
Returns:
Number of rows affected, or -1 on error.

Definition at line 1486 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(), handle_response_peerpoke(), realtime_update_exec(), realtime_update_peer(), sip_poke_noanswer(), and update_realtime_member_field().

01487 {
01488    struct ast_config_engine *eng;
01489    int res = -1;
01490    char db[256]="";
01491    char table[256]="";
01492    va_list ap;
01493 
01494    va_start(ap, lookup);
01495    eng = find_engine(family, db, sizeof(db), table, sizeof(table));
01496    if (eng && eng->update_func) 
01497       res = eng->update_func(db, table, keyfield, lookup, ap);
01498    va_end(ap);
01499 
01500    return res;
01501 }

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_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 
)

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_next(), ast_variable_retrieve(), authenticate(), check_tx_freq(), collect_function_digits(), conf_exec(), do_directory(), do_say(), do_scheduler(), find_conf(), gtalk_load_config(), handle_save_dialplan(), iax_template_parse(), ind_load_module(), init_logger_chain(), init_manager(), load_config(), load_module(), load_modules(), load_moh_classes(), load_odbc_config(), load_rpt_vars(), loadconfigurationfile(), misdn_cfg_init(), node_lookup(), odbc_load_module(), osp_create_provider(), parse_config(), pbx_load_config(), process_my_load_module(), read_agent_config(), read_config_maps(), reload(), reload_config(), reload_followme(), reload_queues(), set_config(), setup_dahdi(), sip_notify(), sla_build_station(), sla_build_trunk(), smdi_load(), store_config(), and tds_load_module().

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,
char *  variable,
char *  match 
)

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

00486 {
00487    struct ast_variable *cur, *prev=NULL, *curn;
00488    int res = -1;
00489    cur = category->root;
00490    while (cur) {
00491       if (cur->name == variable) {
00492          if (prev) {
00493             prev->next = cur->next;
00494             if (cur == category->last)
00495                category->last = prev;
00496          } else {
00497             category->root = cur->next;
00498             if (cur == category->last)
00499                category->last = NULL;
00500          }
00501          cur->next = NULL;
00502          ast_variables_destroy(cur);
00503          return 0;
00504       }
00505       prev = cur;
00506       cur = cur->next;
00507    }
00508 
00509    prev = NULL;
00510    cur = category->root;
00511    while (cur) {
00512       curn = cur->next;
00513       if (!strcasecmp(cur->name, variable) && (ast_strlen_zero(match) || !strcasecmp(cur->value, match))) {
00514          if (prev) {
00515             prev->next = cur->next;
00516             if (cur == category->last)
00517                category->last = prev;
00518          } else {
00519             category->root = cur->next;
00520             if (cur == category->last)
00521                category->last = NULL;
00522          }
00523          cur->next = NULL;
00524          ast_variables_destroy(cur);
00525          res = 0;
00526       } else
00527          prev = cur;
00528 
00529       cur = curn;
00530    }
00531    return res;
00532 }

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 apply_outgoing(), ast_channeltype_list(), 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(), parse_cookies(), 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 }

struct ast_variable* ast_variable_next ( struct ast_config config,
char *  category,
struct ast_variable prev 
)

Iterates through variables.

Somewhat similar in intent as the ast_category_browse. The prev variable MUST be an actual pointer to an actual variable (such as one obtained by using ast_variable_browse() or ast_variable_next() itself). List variables of config file Returns next variable on the list, or NULL on failure

Definition at line 250 of file config.c.

References ast_variable_browse(), and config.

00251 {
00252    struct ast_variable *v = NULL;
00253    v = ast_variable_browse(config, category);
00254    if(v) {
00255      if(prev) {
00256       while (v) {
00257         if (v == prev)
00258          return v->next;
00259         v=v->next;
00260       }
00261      } else {
00262       return v;
00263      }
00264    }
00265    return NULL;
00266 }

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

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

Referenced by advanced_options(), aji_load_config(), ast_config_option(), ast_rtp_reload(), ast_udptl_reload(), directory_exec(), do_directory(), do_reload(), do_scheduler(), festival_exec(), 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_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(), reload_config(), reload_followme(), reload_queues(), retreive_memory(), retrieve_astcfgint(), rpt(), rpt_master(), rpt_tele_thread(), set_config(), setup_dahdi(), sla_build_station(), sla_build_trunk(), sla_load_config(), tds_load_module(), telem_lookup(), update_realtime_members(), vm_change_password(), and vm_forwardoptions().

00270 {
00271    struct ast_variable *v;
00272 
00273    if (category) {
00274       for (v = ast_variable_browse(config, category); v; v = v->next) {
00275          if (!strcasecmp(variable, v->name))
00276             return v->value;
00277       }
00278    } else {
00279       struct ast_category *cat;
00280 
00281       for (cat = config->root; cat; cat = cat->next)
00282          for (v = cat->root; v; v = v->next)
00283             if (!strcasecmp(variable, v->name))
00284                return v->value;
00285    }
00286 
00287    return NULL;
00288 }

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

Definition at line 534 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(), vm_change_password(), and vm_forwardoptions().

00536 {
00537    struct ast_variable *cur, *prev=NULL, *newer;
00538 
00539    if (!(newer = ast_variable_new(variable, value)))
00540       return -1;
00541    
00542    newer->object = object;
00543 
00544    for (cur = category->root; cur; prev = cur, cur = cur->next) {
00545       if (strcasecmp(cur->name, variable) ||
00546          (!ast_strlen_zero(match) && strcasecmp(cur->value, match)))
00547          continue;
00548 
00549       newer->next = cur->next;
00550       newer->object = cur->object || object;
00551       if (prev)
00552          prev->next = newer;
00553       else
00554          category->root = newer;
00555       if (category->last == cur)
00556          category->last = newer;
00557 
00558       cur->next = NULL;
00559       ast_variables_destroy(cur);
00560 
00561       return 0;
00562    }
00563 
00564    if (prev)
00565       prev->next = newer;
00566    else
00567       category->root = newer;
00568 
00569    return 0;
00570 }

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_destroy(), ast_httpd_helper_thread(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_variable_delete(), ast_variable_update(), build_peer(), build_user(), cli_realtime_load(), find_conf_realtime(), find_user_realtime(), handle_uri(), load_realtime_queue(), pvt_destructor(), queue_function_queuewaitingcount(), realtime_alias(), realtime_canmatch(), realtime_exec(), realtime_exists(), realtime_matchmore(), realtime_odbc(), realtime_peer(), realtime_user(), sip_alloc(), sip_destroy_peer(), sip_destroy_user(), update_realtime_member_field(), 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 }

static struct ast_category* category_get ( const struct ast_config config,
const char *  category_name,
int  ignored 
) [static]

Definition at line 330 of file config.c.

References config, ast_category::ignored, ast_category::name, and ast_category::next.

Referenced by ast_category_get(), and process_text_line().

00331 {
00332    struct ast_category *cat;
00333 
00334    /* try exact match first, then case-insensitive match */
00335    for (cat = config->root; cat; cat = cat->next) {
00336       if (cat->name == category_name && (ignored || !cat->ignored))
00337          return cat;
00338    }
00339 
00340    for (cat = config->root; cat; cat = cat->next) {
00341       if (!strcasecmp(cat->name, category_name) && (ignored || !cat->ignored))
00342          return cat;
00343    }
00344 
00345    return NULL;
00346 }

static void CB_ADD ( char **  comment_buffer,
int *  comment_buffer_size,
char *  str 
) [static]

Definition at line 93 of file config.c.

References ast_realloc, and CB_INCR.

Referenced by config_text_file_load().

00094 {
00095    int rem = *comment_buffer_size - strlen(*comment_buffer) - 1;
00096    int siz = strlen(str);
00097    if (rem < siz+1) {
00098       *comment_buffer = ast_realloc(*comment_buffer, *comment_buffer_size + CB_INCR + siz + 1);
00099       if (!(*comment_buffer))
00100          return;
00101       *comment_buffer_size += CB_INCR+siz+1;
00102    }
00103    strcat(*comment_buffer,str);
00104 }

static void CB_ADD_LEN ( char **  comment_buffer,
int *  comment_buffer_size,
char *  str,
int  len 
) [static]

Definition at line 106 of file config.c.

References ast_realloc, and CB_INCR.

Referenced by config_text_file_load().

00107 {
00108    int cbl = strlen(*comment_buffer) + 1;
00109    int rem = *comment_buffer_size - cbl;
00110    if (rem < len+1) {
00111       *comment_buffer = ast_realloc(*comment_buffer, *comment_buffer_size + CB_INCR + len + 1);
00112       if (!(*comment_buffer))
00113          return;
00114       *comment_buffer_size += CB_INCR+len+1;
00115    }
00116    strncat(*comment_buffer,str,len);
00117    (*comment_buffer)[cbl+len-1] = 0;
00118 }

static void CB_INIT ( char **  comment_buffer,
int *  comment_buffer_size,
char **  lline_buffer,
int *  lline_buffer_size 
) [static]

Definition at line 74 of file config.c.

References ast_malloc, and CB_INCR.

Referenced by config_text_file_load().

00075 {
00076    if (!(*comment_buffer)) {
00077       *comment_buffer = ast_malloc(CB_INCR);
00078       if (!(*comment_buffer))
00079          return;
00080       (*comment_buffer)[0] = 0;
00081       *comment_buffer_size = CB_INCR;
00082       *lline_buffer = ast_malloc(CB_INCR);
00083       if (!(*lline_buffer))
00084          return;
00085       (*lline_buffer)[0] = 0;
00086       *lline_buffer_size = CB_INCR;
00087    } else {
00088       (*comment_buffer)[0] = 0;
00089       (*lline_buffer)[0] = 0;
00090    }
00091 }

static void CB_RESET ( char **  comment_buffer,
char **  lline_buffer 
) [static]

Definition at line 133 of file config.c.

Referenced by process_text_line().

00134 { 
00135    (*comment_buffer)[0] = 0; 
00136    (*lline_buffer)[0] = 0;
00137 }

static void clear_config_maps ( void   )  [static]

Definition at line 1163 of file config.c.

References ast_mutex_lock(), ast_mutex_unlock(), config_lock, config_maps, free, map, and ast_config_map::next.

Referenced by read_config_maps().

01164 {
01165    struct ast_config_map *map;
01166 
01167    ast_mutex_lock(&config_lock);
01168 
01169    while (config_maps) {
01170       map = config_maps;
01171       config_maps = config_maps->next;
01172       free(map);
01173    }
01174       
01175    ast_mutex_unlock(&config_lock);
01176 }

static int config_command ( int  fd,
int  argc,
char **  argv 
) [static]

Definition at line 1503 of file config.c.

References ast_cli(), ast_mutex_lock(), config_engine_list, config_lock, config_maps, map, ast_config_engine::name, and ast_config_engine::next.

01504 {
01505    struct ast_config_engine *eng;
01506    struct ast_config_map *map;
01507    
01508    ast_mutex_lock(&config_lock);
01509 
01510    ast_cli(fd, "\n\n");
01511    for (eng = config_engine_list; eng; eng = eng->next) {
01512       ast_cli(fd, "\nConfig Engine: %s\n", eng->name);
01513       for (map = config_maps; map; map = map->next)
01514          if (!strcasecmp(map->driver, eng->name)) {
01515             ast_cli(fd, "===> %s (db=%s, table=%s)\n", map->name, map->database,
01516                map->table ? map->table : map->name);
01517          }
01518    }
01519    ast_cli(fd,"\n\n");
01520    
01521    ast_mutex_unlock(&config_lock);
01522 
01523    return 0;
01524 }

static struct ast_config* config_text_file_load ( const char *  database,
const char *  table,
const char *  filename,
struct ast_config cfg,
int  withcomments 
) [static]

Definition at line 831 of file config.c.

References ast_config_AST_CONFIG_DIR, ast_config_get_current_category(), ast_copy_string(), ast_log(), ast_strip(), ast_strlen_zero(), ast_verbose(), CB_ADD(), CB_ADD_LEN(), CB_INIT(), COMMENT_META, COMMENT_TAG, errno, f, LLB_ADD(), LOG_DEBUG, LOG_ERROR, LOG_WARNING, MAX_NESTED_COMMENTS, option_debug, option_verbose, process_text_line(), and VERBOSE_PREFIX_2.

00832 {
00833    char fn[256];
00834 #if defined(LOW_MEMORY)
00835    char buf[512];
00836 #else
00837    char buf[8192];
00838 #endif
00839    char *new_buf, *comment_p, *process_buf;
00840    FILE *f;
00841    int lineno=0;
00842    int comment = 0, nest[MAX_NESTED_COMMENTS];
00843    struct ast_category *cat = NULL;
00844    int count = 0;
00845    struct stat statbuf;
00846    /*! Growable string buffer */
00847    char *comment_buffer=0;   /*!< this will be a comment collector.*/
00848    int   comment_buffer_size=0;  /*!< the amount of storage so far alloc'd for the comment_buffer */
00849 
00850    char *lline_buffer=0;    /*!< A buffer for stuff behind the ; */
00851    int  lline_buffer_size=0;
00852 
00853    
00854    cat = ast_config_get_current_category(cfg);
00855 
00856    if (filename[0] == '/') {
00857       ast_copy_string(fn, filename, sizeof(fn));
00858    } else {
00859       snprintf(fn, sizeof(fn), "%s/%s", (char *)ast_config_AST_CONFIG_DIR, filename);
00860    }
00861 
00862    if (withcomments) {
00863       CB_INIT(&comment_buffer, &comment_buffer_size, &lline_buffer, &lline_buffer_size);
00864       if (!lline_buffer || !comment_buffer) {
00865          ast_log(LOG_ERROR, "Failed to initialize the comment buffer!\n");
00866          return NULL;
00867       }
00868    }
00869 #ifdef AST_INCLUDE_GLOB
00870    {
00871       int glob_ret;
00872       glob_t globbuf;
00873       globbuf.gl_offs = 0; /* initialize it to silence gcc */
00874 #ifdef SOLARIS
00875       glob_ret = glob(fn, GLOB_NOCHECK, NULL, &globbuf);
00876 #else
00877       glob_ret = glob(fn, GLOB_NOMAGIC|GLOB_BRACE, NULL, &globbuf);
00878 #endif
00879       if (glob_ret == GLOB_NOSPACE)
00880          ast_log(LOG_WARNING,
00881             "Glob Expansion of pattern '%s' failed: Not enough memory\n", fn);
00882       else if (glob_ret  == GLOB_ABORTED)
00883          ast_log(LOG_WARNING,
00884             "Glob Expansion of pattern '%s' failed: Read error\n", fn);
00885       else  {
00886          /* loop over expanded files */
00887          int i;
00888          for (i=0; i<globbuf.gl_pathc; i++) {
00889             ast_copy_string(fn, globbuf.gl_pathv[i], sizeof(fn));
00890 #endif
00891    do {
00892       if (stat(fn, &statbuf))
00893          continue;
00894 
00895       if (!S_ISREG(statbuf.st_mode)) {
00896          ast_log(LOG_WARNING, "'%s' is not a regular file, ignoring\n", fn);
00897          continue;
00898       }
00899       if (option_verbose > 1) {
00900          ast_verbose(VERBOSE_PREFIX_2 "Parsing '%s': ", fn);
00901          fflush(stdout);
00902       }
00903       if (!(f = fopen(fn, "r"))) {
00904          if (option_debug)
00905             ast_log(LOG_DEBUG, "No file to parse: %s\n", fn);
00906          if (option_verbose > 1)
00907             ast_verbose( "Not found (%s)\n", strerror(errno));
00908          continue;
00909       }
00910       count++;
00911       if (option_debug)
00912          ast_log(LOG_DEBUG, "Parsing %s\n", fn);
00913       if (option_verbose > 1)
00914          ast_verbose("Found\n");
00915       while(!feof(f)) {
00916          lineno++;
00917          if (fgets(buf, sizeof(buf), f)) {
00918             if ( withcomments ) {
00919                CB_ADD(&comment_buffer, &comment_buffer_size, lline_buffer);       /* add the current lline buffer to the comment buffer */
00920                lline_buffer[0] = 0;        /* erase the lline buffer */
00921             }
00922             
00923             new_buf = buf;
00924             if (comment) 
00925                process_buf = NULL;
00926             else
00927                process_buf = buf;
00928             
00929             while ((comment_p = strchr(new_buf, COMMENT_META))) {
00930                if ((comment_p > new_buf) && (*(comment_p-1) == '\\')) {
00931                   /* Escaped semicolons aren't comments. */
00932                   new_buf = comment_p + 1;
00933                } else if(comment_p[1] == COMMENT_TAG && comment_p[2] == COMMENT_TAG && (comment_p[3] != '-')) {
00934                   /* Meta-Comment start detected ";--" */
00935                   if (comment < MAX_NESTED_COMMENTS) {
00936                      *comment_p = '\0';
00937                      new_buf = comment_p + 3;
00938                      comment++;
00939                      nest[comment-1] = lineno;
00940                   } else {
00941                      ast_log(LOG_ERROR, "Maximum nest limit of %d reached.\n", MAX_NESTED_COMMENTS);
00942                   }
00943                } else if ((comment_p >= new_buf + 2) &&
00944                      (*(comment_p - 1) == COMMENT_TAG) &&
00945                      (*(comment_p - 2) == COMMENT_TAG)) {
00946                   /* Meta-Comment end detected */
00947                   comment--;
00948                   new_buf = comment_p + 1;
00949                   if (!comment) {
00950                      /* Back to non-comment now */
00951                      if (process_buf) {
00952                         /* Actually have to move what's left over the top, then continue */
00953                         char *oldptr;
00954                         oldptr = process_buf + strlen(process_buf);
00955                         if ( withcomments ) {
00956                            CB_ADD(&comment_buffer, &comment_buffer_size, ";");
00957                            CB_ADD_LEN(&comment_buffer, &comment_buffer_size, oldptr+1, new_buf-oldptr-1);
00958                         }
00959                         
00960                         memmove(oldptr, new_buf, strlen(new_buf) + 1);
00961                         new_buf = oldptr;
00962                      } else
00963                         process_buf = new_buf;
00964                   }
00965                } else {
00966                   if (!comment) {
00967                      /* If ; is found, and we are not nested in a comment, 
00968                         we immediately stop all comment processing */
00969                      if ( withcomments ) {
00970                         LLB_ADD(&lline_buffer, &lline_buffer_size, comment_p);
00971                      }
00972                      *comment_p = '\0'; 
00973                      new_buf = comment_p;
00974                   } else
00975                      new_buf = comment_p + 1;
00976                }
00977             }
00978             if( withcomments && comment && !process_buf )
00979             {
00980                CB_ADD(&comment_buffer, &comment_buffer_size, buf);  /* the whole line is a comment, store it */
00981             }
00982             
00983             if (process_buf) {
00984                char *buf = ast_strip(process_buf);
00985                if (!ast_strlen_zero(buf)) {
00986                   if (process_text_line(cfg, &cat, buf, lineno, fn, withcomments, &comment_buffer, &comment_buffer_size, &lline_buffer, &lline_buffer_size)) {
00987                      cfg = NULL;
00988                      break;
00989                   }
00990                }
00991             }
00992          }
00993       }
00994       fclose(f);     
00995    } while(0);
00996    if (comment) {
00997       ast_log(LOG_WARNING,"Unterminated comment detected beginning on line %d\n", nest[comment - 1]);
00998    }
00999 #ifdef AST_INCLUDE_GLOB
01000                if (!cfg)
01001                   break;
01002             }
01003             globfree(&globbuf);
01004          }
01005       }
01006 #endif
01007 
01008    if (cfg && cfg->include_level == 1 && withcomments && comment_buffer) {
01009       free(comment_buffer);
01010       free(lline_buffer);
01011       comment_buffer = NULL;
01012       lline_buffer = NULL;
01013       comment_buffer_size = 0;
01014       lline_buffer_size = 0;
01015    }
01016    
01017    if (count == 0)
01018       return NULL;
01019 
01020    return cfg;
01021 }

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

Definition at line 1023 of file config.c.

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

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

01024 {
01025    FILE *f = NULL;
01026    int fd = -1;
01027    char fn[256], fntmp[256];
01028    char date[256]="";
01029    time_t t;
01030    struct ast_variable *var;
01031    struct ast_category *cat;
01032    struct ast_comment *cmt;
01033    struct stat s;
01034    int blanklines = 0;
01035    int stat_result = 0;
01036 
01037    if (configfile[0] == '/') {
01038       snprintf(fntmp, sizeof(fntmp), "%s.XXXXXX", configfile);
01039       ast_copy_string(fn, configfile, sizeof(fn));
01040    } else {
01041       snprintf(fntmp, sizeof(fntmp), "%s/%s.XXXXXX", ast_config_AST_CONFIG_DIR, configfile);
01042       snprintf(fn, sizeof(fn), "%s/%s", ast_config_AST_CONFIG_DIR, configfile);
01043    }
01044    time(&t);
01045    ast_copy_string(date, ctime(&t), sizeof(date));
01046    if ((fd = mkstemp(fntmp)) > 0 && (f = fdopen(fd, "w")) != NULL) {
01047       if (option_verbose > 1)
01048          ast_verbose(VERBOSE_PREFIX_2 "Saving '%s': ", fn);
01049       fprintf(f, ";!\n");
01050       fprintf(f, ";! Automatically generated configuration file\n");
01051       if (strcmp(configfile, fn))
01052          fprintf(f, ";! Filename: %s (%s)\n", configfile, fn);
01053       else
01054          fprintf(f, ";! Filename: %s\n", configfile);
01055       fprintf(f, ";! Generator: %s\n", generator);
01056       fprintf(f, ";! Creation Date: %s", date);
01057       fprintf(f, ";!\n");
01058       cat = cfg->root;
01059       while(cat) {
01060          /* Dump section with any appropriate comment */
01061          for (cmt = cat->precomments; cmt; cmt=cmt->next)
01062          {
01063             if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
01064                fprintf(f,"%s", cmt->cmt);
01065          }
01066          if (!cat->precomments)
01067             fprintf(f,"\n");
01068          fprintf(f, "[%s]", cat->name);
01069          if (cat->ignored || !AST_LIST_EMPTY(&cat->template_instances)) {
01070             fprintf(f, "(");
01071             if (cat->ignored) {
01072                fprintf(f, "!");
01073             }
01074             if (cat->ignored && !AST_LIST_EMPTY(&cat->template_instances)) {
01075                fprintf(f, ",");
01076             }
01077             if (!AST_LIST_EMPTY(&cat->template_instances)) {
01078                struct ast_category_template_instance *x;
01079                AST_LIST_TRAVERSE(&cat->template_instances, x, next) {
01080                   fprintf(f,"%s",x->name);
01081                   if (x != AST_LIST_LAST(&cat->template_instances))
01082                      fprintf(f,",");
01083                }
01084             }
01085             fprintf(f, ")");
01086          }
01087          for(cmt = cat->sameline; cmt; cmt=cmt->next)
01088          {
01089             fprintf(f,"%s", cmt->cmt);
01090          }
01091          if (!cat->sameline)
01092             fprintf(f,"\n");
01093          var = cat->root;
01094          while(var) {
01095             struct ast_category_template_instance *x;
01096             struct ast_variable *v2;
01097             int found = 0;
01098             AST_LIST_TRAVERSE(&cat->template_instances, x, next) {
01099                
01100                for (v2 = x->inst->root; v2; v2 = v2->next) {
01101                   if (!strcasecmp(var->name, v2->name))
01102                      break;
01103                }
01104                if (v2 && v2->value && !strcmp(v2->value, var->value)) {
01105                   found = 1;
01106                   break;
01107                }
01108             }
01109             if (found) {
01110                var = var->next;
01111                continue;
01112             }
01113             for (cmt = var->precomments; cmt; cmt=cmt->next)
01114             {
01115                if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!')
01116                   fprintf(f,"%s", cmt->cmt);
01117             }
01118             if (var->sameline) 
01119                fprintf(f, "%s %s %s  %s", var->name, (var->object ? "=>" : "="), var->value, var->sameline->cmt);
01120             else  
01121                fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="), var->value);
01122             if (var->blanklines) {
01123                blanklines = var->blanklines;
01124                while (blanklines--)
01125                   fprintf(f, "\n");
01126             }
01127                
01128             var = var->next;
01129          }
01130 #if 0
01131          /* Put an empty line */
01132          fprintf(f, "\n");
01133 #endif
01134          cat = cat->next;
01135       }
01136       if ((option_verbose > 1) && !option_debug)
01137          ast_verbose("Saved\n");
01138    } else {
01139       if (option_debug)
01140          ast_log(LOG_DEBUG, "Unable to open for writing: %s (%s)\n", fn, strerror(errno));
01141       if (option_verbose > 1)
01142          ast_verbose(VERBOSE_PREFIX_2 "Unable to write %s (%s)", fn, strerror(errno));
01143       if (fd > -1)
01144          close(fd);
01145       return -1;
01146    }
01147    if (!(stat_result = stat(fn, &s))) {
01148       fchmod(fd, s.st_mode);
01149    }
01150    fclose(f);
01151    if ((!stat_result && unlink(fn)) || link(fntmp, fn)) {
01152       if (option_debug)
01153          ast_log(LOG_DEBUG, "Unable to open for writing: %s (%s)\n", fn, strerror(errno));
01154       if (option_verbose > 1)
01155          ast_verbose(VERBOSE_PREFIX_2 "Unable to write %s (%s)", fn, strerror(errno));
01156       unlink(fntmp);
01157       return -1;
01158    }
01159    unlink(fntmp);
01160    return 0;
01161 }

static struct ast_config_engine* find_engine ( const char *  family,
char *  database,
int  dbsiz,
char *  table,
int  tabsiz 
) [static]

Find realtime engine for realtime family.

Definition at line 1323 of file config.c.

References ast_copy_string(), ast_mutex_lock(), config_lock, config_maps, and map.

Referenced by ast_check_realtime(), ast_config_internal_load(), ast_load_realtime(), ast_load_realtime_multientry(), ast_speech_new(), ast_speech_register(), and ast_update_realtime().

01324 {
01325    struct ast_config_engine *eng, *ret = NULL;
01326    struct ast_config_map *map;
01327 
01328    ast_mutex_lock(&config_lock);
01329 
01330    for (map = config_maps; map; map = map->next) {
01331       if (!strcasecmp(family, map->name)) {
01332          if (database)
01333             ast_copy_string(database, map->database, dbsiz);
01334          if (table)
01335             ast_copy_string(table, map->table ? map->table : family, tabsiz);
01336          break;
01337       }
01338    }
01339 
01340    /* Check if the required driver (engine) exist */
01341    if (map) {
01342       for (eng = config_engine_list; !ret && eng; eng = eng->next) {
01343          if (!strcasecmp(eng->name, map->driver))
01344             ret = eng;
01345       }
01346    }
01347 
01348    ast_mutex_unlock(&config_lock);
01349    
01350    /* if we found a mapping, but the engine is not available, then issue a warning */
01351    if (map && !ret)
01352       ast_log(LOG_WARNING, "Realtime mapping for '%s' found to engine '%s', but the engine is not available\n", map->name, map->driver);
01353 
01354    return ret;
01355 }

static void inherit_category ( struct ast_category new,
const struct ast_category base 
) [static]

Definition at line 465 of file config.c.

References ast_calloc, AST_LIST_INSERT_TAIL, ast_variable_append(), ast_category_template_instance::inst, ast_category::name, ast_category_template_instance::name, ast_category_template_instance::next, ast_category::root, ast_category::template_instances, var, and variable_clone().

Referenced by process_text_line().

00466 {
00467    struct ast_variable *var;
00468    struct ast_category_template_instance *x = ast_calloc(1,sizeof(struct ast_category_template_instance));
00469    strcpy(x->name, base->name);
00470    x->inst = base;
00471    AST_LIST_INSERT_TAIL(&new->template_instances, x, next);
00472    for (var = base->root; var; var = var->next)
00473       ast_variable_append(new, variable_clone(var));
00474 }

static void LLB_ADD ( char **  lline_buffer,
int *  lline_buffer_size,
char *  str 
) [static]

Definition at line 120 of file config.c.

References ast_realloc, and CB_INCR.

Referenced by config_text_file_load().

00121 {
00122    int rem = *lline_buffer_size - strlen(*lline_buffer) - 1;
00123    int siz = strlen(str);
00124    if (rem < siz+1) {
00125       *lline_buffer = ast_realloc(*lline_buffer, *lline_buffer_size + CB_INCR + siz + 1);
00126       if (!(*lline_buffer)) 
00127          return;
00128       *lline_buffer_size += CB_INCR + siz + 1;
00129    }
00130    strcat(*lline_buffer,str);
00131 }

static void move_variables ( struct ast_category old,
struct ast_category new 
) [static]

Definition at line 304 of file config.c.

References ast_variable_append(), ast_category_template_instance::next, ast_category::root, and var.

Referenced by process_text_line().

00305 {
00306    struct ast_variable *var = old->root;
00307    old->root = NULL;
00308 #if 1
00309    /* we can just move the entire list in a single op */
00310    ast_variable_append(new, var);
00311 #else
00312    while (var) {
00313       struct ast_variable *next = var->next;
00314       var->next = NULL;
00315       ast_variable_append(new, var);
00316       var = next;
00317    }
00318 #endif
00319 }

static struct ast_category* next_available_category ( struct ast_category cat  )  [static]

Definition at line 402 of file config.c.

References ast_category::ignored, and ast_category::next.

Referenced by ast_category_browse().

00403 {
00404    for (; cat && cat->ignored; cat = cat->next);
00405 
00406    return cat;
00407 }

static int process_text_line ( struct ast_config cfg,
struct ast_category **  cat,
char *  buf,
int  lineno,
const char *  configfile,
int  withcomments,
char **  comment_buffer,
int *  comment_buffer_size,
char **  lline_buffer,
int *  lline_buffer_size 
) [static]

Definition at line 643 of file config.c.

References ALLOC_COMMENT(), ast_category_append(), ast_category_destroy(), ast_category_new(), ast_config_internal_load(), ast_log(), ast_opt_exec_includes, ast_safe_system(), ast_skip_blanks(), ast_strip(), ast_strlen_zero(), ast_variable_append(), ast_variable_new(), ast_variable::blanklines, category_get(), CB_RESET(), inherit_category(), ast_variable::lineno, LOG_ERROR, LOG_WARNING, move_variables(), ast_variable::object, ast_variable::precomments, ast_category::precomments, ast_variable::sameline, and ast_category::sameline.

Referenced by config_text_file_load().

00645 {
00646    char *c;
00647    char *cur = buf;
00648    struct ast_variable *v;
00649    char cmd[512], exec_file[512];
00650    int object, do_exec, do_include;
00651 
00652    /* Actually parse the entry */
00653    if (cur[0] == '[') {
00654       struct ast_category *newcat = NULL;
00655       char *catname;
00656 
00657       /* A category header */
00658       c = strchr(cur, ']');
00659       if (!c) {
00660          ast_log(LOG_WARNING, "parse error: no closing ']', line %d of %s\n", lineno, configfile);
00661          return -1;
00662       }
00663       *c++ = '\0';
00664       cur++;
00665       if (*c++ != '(')
00666          c = NULL;
00667       catname = cur;
00668       if (!(*cat = newcat = ast_category_new(catname))) {
00669          return -1;
00670       }
00671       /* add comments */
00672       if (withcomments && *comment_buffer && (*comment_buffer)[0] ) {
00673          newcat->precomments = ALLOC_COMMENT(*comment_buffer);
00674       }
00675       if (withcomments && *lline_buffer && (*lline_buffer)[0] ) {
00676          newcat->sameline = ALLOC_COMMENT(*lline_buffer);
00677       }
00678       if( withcomments )
00679          CB_RESET(comment_buffer, lline_buffer);
00680       
00681       /* If there are options or categories to inherit from, process them now */
00682       if (c) {
00683          if (!(cur = strchr(c, ')'))) {
00684             ast_log(LOG_WARNING, "parse error: no closing ')', line %d of %s\n", lineno, configfile);
00685             return -1;
00686          }
00687          *cur = '\0';
00688          while ((cur = strsep(&c, ","))) {
00689             if (!strcasecmp(cur, "!")) {
00690                (*cat)->ignored = 1;
00691             } else if (!strcasecmp(cur, "+")) {
00692                *cat = category_get(cfg, catname, 1);
00693                if (!(*cat)) {
00694                   if (newcat)
00695                      ast_category_destroy(newcat);
00696                   ast_log(LOG_WARNING, "Category addition requested, but category '%s' does not exist, line %d of %s\n", catname, lineno, configfile);
00697                   return -1;
00698                }
00699                if (newcat) {
00700                   move_variables(newcat, *cat);
00701                   ast_category_destroy(newcat);
00702                   newcat = NULL;
00703                }
00704             } else {
00705                struct ast_category *base;
00706             
00707                base = category_get(cfg, cur, 1);
00708                if (!base) {
00709                   ast_log(LOG_WARNING, "Inheritance requested, but category '%s' does not exist, line %d of %s\n", cur, lineno, configfile);
00710                   return -1;
00711                }
00712                inherit_category(*cat, base);
00713             }
00714          }
00715       }
00716       if (newcat)
00717          ast_category_append(cfg, *cat);
00718    } else if (cur[0] == '#') {
00719       /* A directive */
00720       cur++;
00721       c = cur;
00722       while(*c && (*c > 32)) c++;
00723       if (*c) {
00724          *c = '\0';
00725          /* Find real argument */
00726          c = ast_skip_blanks(c + 1);
00727          if (!(*c))
00728             c = NULL;
00729       } else 
00730          c = NULL;
00731       do_include = !strcasecmp(cur, "include");
00732       if(!do_include)
00733          do_exec = !strcasecmp(cur, "exec");
00734       else
00735          do_exec = 0;
00736       if (do_exec && !ast_opt_exec_includes) {
00737          ast_log(LOG_WARNING, "Cannot perform #exec unless execincludes option is enabled in asterisk.conf (options section)!\n");
00738          do_exec = 0;
00739       }
00740       if (do_include || do_exec) {
00741          if (c) {
00742             /* Strip off leading and trailing "'s and <>'s */
00743             while((*c == '<') || (*c == '>') || (*c == '\"')) c++;
00744             /* Get rid of leading mess */
00745             cur = c;
00746             while (!ast_strlen_zero(cur)) {
00747                c = cur + strlen(cur) - 1;
00748                if ((*c == '>') || (*c == '<') || (*c == '\"'))
00749                   *c = '\0';
00750                else
00751                   break;
00752             }
00753             /* #exec </path/to/executable>
00754                We create a tmp file, then we #include it, then we delete it. */
00755             if (do_exec) { 
00756                snprintf(exec_file, sizeof(exec_file), "/var/tmp/exec.%d.%ld", (int)time(NULL), (long)pthread_self());
00757                snprintf(cmd, sizeof(cmd), "%s > %s 2>&1", cur, exec_file);
00758                ast_safe_system(cmd);
00759                cur = exec_file;
00760             } else
00761                exec_file[0] = '\0';
00762             /* A #include */
00763             do_include = ast_config_internal_load(cur, cfg, withcomments) ? 1 : 0;
00764             if(!ast_strlen_zero(exec_file))
00765                unlink(exec_file);
00766             if (!do_include) {
00767                ast_log(LOG_ERROR, "*********************************************************\n");
00768                ast_log(LOG_ERROR, "*********** YOU SHOULD REALLY READ THIS ERROR ***********\n");
00769                ast_log(LOG_ERROR, "Future versions of Asterisk will treat a #include of a "
00770                                   "file that does not exist as an error, and will fail to "
00771                                   "load that configuration file.  Please ensure that the "
00772                                   "file '%s' exists, even if it is empty.\n", cur);
00773                ast_log(LOG_ERROR, "*********** YOU SHOULD REALLY READ THIS ERROR ***********\n");
00774                ast_log(LOG_ERROR, "*********************************************************\n");
00775                return 0;
00776             }
00777 
00778          } else {
00779             ast_log(LOG_WARNING, "Directive '#%s' needs an argument (%s) at line %d of %s\n", 
00780                   do_exec ? "exec" : "include",
00781                   do_exec ? "/path/to/executable" : "filename",
00782                   lineno,
00783                   configfile);
00784          }
00785       }
00786       else 
00787          ast_log(LOG_WARNING, "Unknown directive '#%s' at line %d of %s\n", cur, lineno, configfile);
00788    } else {
00789       /* Just a line (variable = value) */
00790       if (!(*cat)) {
00791          ast_log(LOG_WARNING,
00792             "parse error: No category context for line %d of %s\n", lineno, configfile);
00793          return -1;
00794       }
00795       c = strchr(cur, '=');
00796       if (c) {
00797          *c = 0;
00798          c++;
00799          /* Ignore > in => */
00800          if (*c== '>') {
00801             object = 1;
00802             c++;
00803          } else
00804             object = 0;
00805          if ((v = ast_variable_new(ast_strip(cur), ast_strip(c)))) {
00806             v->lineno = lineno;
00807             v->object = object;
00808             /* Put and reset comments */
00809             v->blanklines = 0;
00810             ast_variable_append(*cat, v);
00811             /* add comments */
00812             if (withcomments && *comment_buffer && (*comment_buffer)[0] ) {
00813                v->precomments = ALLOC_COMMENT(*comment_buffer);
00814             }
00815             if (withcomments && *lline_buffer && (*lline_buffer)[0] ) {
00816                v->sameline = ALLOC_COMMENT(*lline_buffer);
00817             }
00818             if( withcomments )
00819                CB_RESET(comment_buffer, lline_buffer);
00820             
00821          } else {
00822             return -1;
00823          }
00824       } else {
00825          ast_log(LOG_WARNING, "No '=' (equal sign) in line %d of %s\n", lineno, configfile);
00826       }
00827    }
00828    return 0;
00829 }

int read_config_maps ( void   ) 

Definition at line 1213 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, table, and ast_variable::value.

Referenced by main().

01214 {
01215    struct ast_config *config, *configtmp;
01216    struct ast_variable *v;
01217    char *driver, *table, *database, *stringp, *tmp;
01218 
01219    clear_config_maps();
01220 
01221    configtmp = ast_config_new();
01222    configtmp->max_include_level = 1;
01223    config = ast_config_internal_load(extconfig_conf, configtmp, 0);
01224    if (!config) {
01225       ast_config_destroy(configtmp);
01226       return 0;
01227    }
01228 
01229    for (v = ast_variable_browse(config, "settings"); v; v = v->next) {
01230       stringp = v->value;
01231       driver = strsep(&stringp, ",");
01232 
01233       if ((tmp = strchr(stringp, '\"')))
01234          stringp = tmp;
01235 
01236       /* check if the database text starts with a double quote */
01237       if (*stringp == '"') {
01238          stringp++;
01239          database = strsep(&stringp, "\"");
01240          strsep(&stringp, ",");
01241       } else {
01242          /* apparently this text has no quotes */
01243          database = strsep(&stringp, ",");
01244       }
01245 
01246       table = strsep(&stringp, ",");
01247 
01248       if (!strcmp(v->name, extconfig_conf)) {
01249          ast_log(LOG_WARNING, "Cannot bind '%s'!\n", extconfig_conf);
01250          continue;
01251       }
01252 
01253       if (!strcmp(v->name, "asterisk.conf")) {
01254          ast_log(LOG_WARNING, "Cannot bind 'asterisk.conf'!\n");
01255          continue;
01256       }
01257 
01258       if (!strcmp(v->name, "logger.conf")) {
01259          ast_log(LOG_WARNING, "Cannot bind 'logger.conf'!\n");
01260          continue;
01261       }
01262 
01263       if (!driver || !database)
01264          continue;
01265       if (!strcasecmp(v->name, "sipfriends")) {
01266          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");
01267          append_mapping("sipusers", driver, database, table ? table : "sipfriends");
01268          append_mapping("sippeers", driver, database, table ? table : "sipfriends");
01269       } else if (!strcasecmp(v->name, "iaxfriends")) {
01270          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");
01271          append_mapping("iaxusers", driver, database, table ? table : "iaxfriends");
01272          append_mapping("iaxpeers", driver, database, table ? table : "iaxfriends");
01273       } else 
01274          append_mapping(v->name, driver, database, table);
01275    }
01276       
01277    ast_config_destroy(config);
01278    return 0;
01279 }

int register_config_cli ( void   ) 

Definition at line 1541 of file config.c.

References ast_cli_register_multiple(), and cli_config.

Referenced by main().

01542 {
01543    ast_cli_register_multiple(cli_config, sizeof(cli_config) / sizeof(struct ast_cli_entry));
01544    return 0;
01545 }

static struct ast_variable* variable_clone ( const struct ast_variable old  )  [static]

Definition at line 290 of file config.c.

References ast_variable_new(), ast_variable::blanklines, ast_variable::lineno, ast_variable::name, ast_variable::object, and ast_variable::value.

Referenced by inherit_category().

00291 {
00292    struct ast_variable *new = ast_variable_new(old->name, old->value);
00293 
00294    if (new) {
00295       new->lineno = old->lineno;
00296       new->object = old->object;
00297       new->blanklines = old->blanklines;
00298       /* TODO: clone comments? */
00299    }
00300 
00301    return new;
00302 }


Variable Documentation

struct ast_cli_entry cli_config[] [static]

Initial value:

 {
   { { "core", "show", "config", "mappings", NULL },
   config_command, "Display config mappings (file names to config engines)",
   show_config_help, NULL, &cli_show_config_mappings_deprecated },
}

Definition at line 1535 of file config.c.

Referenced by register_config_cli().

struct ast_cli_entry cli_show_config_mappings_deprecated [static]

Initial value:

 {
   { "show", "config", "mappings", NULL },
   config_command, NULL,
   NULL }

Definition at line 1530 of file config.c.

struct ast_config_engine* config_engine_list [static]

Definition at line 158 of file config.c.

Referenced by ast_config_engine_deregister(), ast_config_engine_register(), ast_config_internal_load(), and config_command().

ast_mutex_t config_lock = ((ast_mutex_t) PTHREAD_MUTEX_INITIALIZER ) [static]

Definition at line 157 of file config.c.

Referenced by ast_config_engine_deregister(), ast_config_engine_register(), clear_config_maps(), config_command(), and find_engine().

struct ast_config_map * config_maps [static]

Referenced by append_mapping(), ast_realtime_enabled(), clear_config_maps(), config_command(), and find_engine().

char* extconfig_conf = "extconfig.conf" [static]

Definition at line 63 of file config.c.

char show_config_help[] [static]

Initial value:

   "Usage: core show config mappings\n"
   "  Shows the filenames to config engines.\n"

Definition at line 1526 of file config.c.

struct ast_config_engine text_file_engine [static]

Initial value:

 {
   .name = "text",
   .load_func = config_text_file_load,
}

Definition at line 1357 of file config.c.

Referenced by ast_config_internal_load().


Generated on Thu May 14 15:13:30 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7