#include "asterisk/utils.h"
#include "asterisk/inline_api.h"
Go to the source code of this file.
Data Structures | |
struct | ast_config_engine |
Configuration engine structure, used to define realtime drivers. More... | |
struct | ast_variable |
Structure for variables, used for configurations and for channel variables. More... | |
Defines | |
#define | ast_config_load(filename, flags) ast_config_load2(filename, AST_MODULE, flags) |
#define | CONFIG_STATUS_FILEUNCHANGED (void *)-1 |
#define | CV_BOOL(__x, __dst) CV_F(__x, (__dst) = ast_true(__val) ) |
helper macros to assign the value to a BOOL, UINT, static string and dynamic string | |
#define | CV_DSTR(__x, __dst) CV_F(__x, if (__dst) ast_free(__dst); __dst = ast_strdup(__val)) |
#define | CV_END } while (0) |
close a variable parsing block | |
#define | CV_F(__pattern, __body) if (!strcasecmp((__var), __pattern)) { __body; break; } |
call a generic function if the name matches. | |
#define | CV_START(__in_var, __in_val) |
the macro to open a block for variable parsing | |
#define | CV_STR(__x, __dst) CV_F(__x, ast_copy_string(__dst, __val, sizeof(__dst))) |
#define | CV_STRFIELD(__x, __obj, __field) CV_F(__x, ast_string_field_set(__obj, __field, __val)) |
#define | CV_UINT(__x, __dst) CV_F(__x, (__dst) = strtoul(__val, NULL, 0) ) |
Typedefs | |
typedef ast_config * | config_load_func (const char *database, const char *table, const char *configfile, struct ast_config *config, struct ast_flags flags, const char *suggested_include_file, const char *who_asked) |
typedef int | realtime_destroy (const char *database, const char *table, const char *keyfield, const char *entity, va_list ap) |
typedef ast_config * | realtime_multi_get (const char *database, const char *table, va_list ap) |
typedef int | realtime_require (const char *database, const char *table, va_list ap) |
Function pointer called to ensure database schema is properly configured for realtime use. | |
typedef int | realtime_store (const char *database, const char *table, va_list ap) |
typedef int | realtime_unload (const char *database, const char *table) |
Function pointer called to clear the database cache and free resources used for such. | |
typedef int | realtime_update (const char *database, const char *table, const char *keyfield, const char *entity, va_list ap) |
typedef ast_variable * | realtime_var_get (const char *database, const char *table, va_list ap) |
Enumerations | |
enum | { CONFIG_FLAG_WITHCOMMENTS = (1 << 0), CONFIG_FLAG_FILEUNCHANGED = (1 << 1), CONFIG_FLAG_NOCACHE = (1 << 2) } |
enum | ast_parse_flags { PARSE_TYPE = 0x000f, PARSE_INT32 = 0x0001, PARSE_UINT32 = 0x0002, PARSE_DOUBLE = 0x0003, PARSE_INADDR = 0x000f, PARSE_DEFAULT = 0x0010, PARSE_IN_RANGE = 0x0020, PARSE_OUT_RANGE = 0x0040, PARSE_PORT_MASK = 0x0300, PARSE_PORT_IGNORE = 0x0100, PARSE_PORT_REQUIRE = 0x0200, PARSE_PORT_FORBID = 0x0300 } |
Support code to parse config file arguments. More... | |
enum | require_type { RQ_INTEGER1, RQ_UINTEGER1, RQ_INTEGER2, RQ_UINTEGER2, RQ_INTEGER3, RQ_UINTEGER3, RQ_INTEGER4, RQ_UINTEGER4, RQ_INTEGER8, RQ_UINTEGER8, RQ_CHAR, RQ_FLOAT, RQ_DATE, RQ_DATETIME } |
Types used in ast_realtime_require_field. More... | |
Functions | |
void | ast_category_append (struct ast_config *config, struct ast_category *cat) |
char * | ast_category_browse (struct ast_config *config, const char *prev) |
Goes through categories. | |
int | ast_category_delete (struct ast_config *cfg, const char *category) |
void | ast_category_destroy (struct ast_category *cat) |
ast_variable * | ast_category_detach_variables (struct ast_category *cat) |
int | ast_category_empty (struct ast_config *cfg, const char *category) |
Removes and destroys all variables within a category. | |
int | ast_category_exist (const struct ast_config *config, const char *category_name) |
Check for category duplicates. | |
ast_variable * | ast_category_first (struct ast_category *cat) |
given a pointer to a category, return the root variable. This is equivalent to ast_variable_browse(), but more efficient if we already have the struct ast_category * (e.g. from ast_category_get()) | |
ast_category * | ast_category_get (const struct ast_config *config, const char *category_name) |
Retrieve a category if it exists. | |
void | ast_category_insert (struct ast_config *config, struct ast_category *cat, const char *match) |
Inserts new category. | |
ast_category * | ast_category_new (const char *name, const char *in_file, int lineno) |
Create a category structure. | |
void | ast_category_rename (struct ast_category *cat, const char *name) |
ast_variable * | ast_category_root (struct ast_config *config, char *cat) |
returns the root ast_variable of a config | |
int | ast_check_realtime (const char *family) |
Check if realtime engine is configured for family. | |
void | ast_config_destroy (struct ast_config *config) |
Destroys a config. | |
int | ast_config_engine_deregister (struct ast_config_engine *del) |
Deregister config engine. | |
int | ast_config_engine_register (struct ast_config_engine *newconfig) |
Register config engine. | |
ast_category * | ast_config_get_current_category (const struct ast_config *cfg) |
Retrieve the current category name being built. API for backend configuration engines while building a configuration set. | |
ast_config * | ast_config_internal_load (const char *configfile, struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl_file, const char *who_asked) |
ast_config * | ast_config_load2 (const char *filename, const char *who_asked, struct ast_flags flags) |
Load a config file. | |
ast_config * | ast_config_new (void) |
Create a new base configuration structure. | |
const char * | ast_config_option (struct ast_config *cfg, const char *cat, const char *var) |
Retrieve a configuration variable within the configuration set. Retrieves the named variable var within category cat of configuration set cfg . If not found, attempts to retrieve the named variable var from within category general. | |
void | ast_config_set_current_category (struct ast_config *cfg, const struct ast_category *cat) |
Set the category within the configuration as being current. API for backend configuration engines while building a configuration set. | |
int | ast_destroy_realtime (const char *family, const char *keyfield, const char *lookup,...) attribute_sentinel |
Destroy realtime configuration. | |
ast_config_include * | ast_include_find (struct ast_config *conf, const char *included_file) |
ast_config_include * | ast_include_new (struct ast_config *conf, const char *from_file, const char *included_file, int is_exec, const char *exec_file, int from_lineno, char *real_included_file_name, int real_included_file_name_size) |
void | ast_include_rename (struct ast_config *conf, const char *from_file, const char *to_file) |
ast_variable * | ast_load_realtime (const char *family,...) attribute_sentinel |
Retrieve realtime configuration. | |
ast_variable * | ast_load_realtime_all (const char *family,...) attribute_sentinel |
ast_config * | ast_load_realtime_multientry (const char *family,...) attribute_sentinel |
Retrieve realtime configuration. | |
int | ast_parse_arg (const char *arg, enum ast_parse_flags flags, void *result,...) |
The argument parsing routine. | |
int | ast_realtime_enabled (void) |
Check if there's any realtime engines loaded. | |
int | ast_realtime_require_field (const char *family,...) attribute_sentinel |
Inform realtime what fields that may be stored. | |
int | ast_rq_is_int (require_type type) |
Check if require type is an integer type. | |
int | ast_store_realtime (const char *family,...) attribute_sentinel |
Create realtime configuration. | |
int | ast_unload_realtime (const char *family) |
Release any resources cached for a realtime family. | |
int | ast_update_realtime (const char *family, const char *keyfield, const char *lookup,...) attribute_sentinel |
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, const char *line) |
void | ast_variable_insert (struct ast_category *category, struct ast_variable *variable, const char *line) |
ast_variable * | ast_variable_new (const char *name, const char *value, const char *filename) |
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) |
Update variable value within a config. | |
void | ast_variables_destroy (struct ast_variable *var) |
Free variable list. | |
int | config_text_file_save (const char *filename, const struct ast_config *cfg, const char *generator) |
int | read_config_maps (void) |
Exposed re-initialization method for core process This method is intended for use only with the core re-initialization and is not designed to be called from any user applications. | |
int | register_config_cli (void) |
Exposed initialization method for core process This method is intended for use only with the core initialization and is not designed to be called from any user applications. |
Definition in file config.h.
#define ast_config_load | ( | filename, | |||
flags | ) | ast_config_load2(filename, AST_MODULE, flags) |
Definition at line 135 of file config.h.
Referenced by adsi_load(), advanced_options(), aji_load_config(), conf_exec(), config_function_read(), config_module(), directory_exec(), festival_exec(), find_conf(), gtalk_load_config(), handle_cli_dialplan_save(), ind_load_module(), jingle_load_config(), load_config(), load_config_meetme(), load_module(), load_moh_classes(), load_odbc_config(), load_rpt_vars(), make_email_file(), node_lookup(), odbc_load_module(), osp_load(), parse_config(), pbx_load_config(), pbx_load_users(), play_message(), prep_email_sub_vars(), read_agent_config(), realtime_directory(), reload(), reload_config(), reload_followme(), reload_queue_rules(), reload_queues(), rpt_master(), set_config(), setup_dahdi(), sla_load_config(), smdi_load(), store_config(), tds_load_module(), vm_change_password(), and vm_forwardoptions().
#define CONFIG_STATUS_FILEUNCHANGED (void *)-1 |
Definition at line 48 of file config.h.
Referenced by __ast_http_load(), __ast_http_post_load(), __ast_rtp_reload(), __ast_udptl_reload(), __init_manager(), _dsp_init(), adsi_load(), aji_load_config(), ast_config_internal_load(), ast_config_load2(), config_function_read(), config_module(), config_text_file_load(), do_reload(), iax_provision_reload(), ind_load_module(), load_config(), load_moh_classes(), misdn_cfg_init(), odbc_load_module(), osp_load(), parse_config(), private_enum_init(), read_agent_config(), reload(), reload_config(), reload_followme(), reload_queue_rules(), reload_queues(), set_config(), setup_dahdi(), sla_load_config(), smdi_load(), and tds_load_module().
#define CV_BOOL | ( | __x, | |||
__dst | ) | CV_F(__x, (__dst) = ast_true(__val) ) |
helper macros to assign the value to a BOOL, UINT, static string and dynamic string
Definition at line 552 of file config.h.
Referenced by store_config_core().
#define CV_DSTR | ( | __x, | |||
__dst | ) | CV_F(__x, if (__dst) ast_free(__dst); __dst = ast_strdup(__val)) |
#define CV_END } while (0) |
close a variable parsing block
Definition at line 544 of file config.h.
Referenced by store_config_core().
#define CV_F | ( | __pattern, | |||
__body | ) | if (!strcasecmp((__var), __pattern)) { __body; break; } |
call a generic function if the name matches.
Definition at line 547 of file config.h.
Referenced by store_config_core().
#define CV_START | ( | __in_var, | |||
__in_val | ) |
Value:
do { \ const char *__var = __in_var; \ const char *__val = __in_val;
Definition at line 538 of file config.h.
Referenced by store_config_core().
#define CV_STR | ( | __x, | |||
__dst | ) | CV_F(__x, ast_copy_string(__dst, __val, sizeof(__dst))) |
#define CV_STRFIELD | ( | __x, | |||
__obj, | |||||
__field | ) | CV_F(__x, ast_string_field_set(__obj, __field, __val)) |
#define CV_UINT | ( | __x, | |||
__dst | ) | CV_F(__x, (__dst) = strtoul(__val, NULL, 0) ) |
typedef struct ast_config* config_load_func(const char *database, const char *table, const char *configfile, struct ast_config *config, struct ast_flags flags, const char *suggested_include_file, const char *who_asked) |
typedef int realtime_destroy(const char *database, const char *table, const char *keyfield, const char *entity, va_list ap) |
typedef struct ast_config* realtime_multi_get(const char *database, const char *table, va_list ap) |
typedef int realtime_require(const char *database, const char *table, va_list ap) |
typedef int realtime_store(const char *database, const char *table, va_list ap) |
typedef int realtime_unload(const char *database, const char *table) |
typedef int realtime_update(const char *database, const char *table, const char *keyfield, const char *entity, va_list ap) |
typedef struct ast_variable* realtime_var_get(const char *database, const char *table, va_list ap) |
anonymous enum |
Options for ast_config_load()
Definition at line 39 of file config.h.
00039 { 00040 /*! Load the configuration, including comments */ 00041 CONFIG_FLAG_WITHCOMMENTS = (1 << 0), 00042 /*! On a reload, give us a -1 if the file hasn't changed. */ 00043 CONFIG_FLAG_FILEUNCHANGED = (1 << 1), 00044 /*! Don't attempt to cache mtime on this config file. */ 00045 CONFIG_FLAG_NOCACHE = (1 << 2), 00046 };
enum ast_parse_flags |
Support code to parse config file arguments.
The function ast_parse_arg() provides a generic interface to parse strings (e.g. numbers, network addresses and so on) in a flexible way, e.g. by doing proper error and bound checks, provide default values, and so on. The function (described later) takes a string as an argument, a set of flags to specify the result format and checks to perform, a pointer to the result, and optionally some additional arguments. It returns 0 on success, != 0 otherwise.
PARSE_TYPE | |
PARSE_INT32 | |
PARSE_UINT32 | |
PARSE_DOUBLE | |
PARSE_INADDR | |
PARSE_DEFAULT | |
PARSE_IN_RANGE | |
PARSE_OUT_RANGE | |
PARSE_PORT_MASK | |
PARSE_PORT_IGNORE | |
PARSE_PORT_REQUIRE | |
PARSE_PORT_FORBID |
Definition at line 443 of file config.h.
00443 { 00444 /* low 4 bits of flags are used for the operand type */ 00445 PARSE_TYPE = 0x000f, 00446 /* numeric types, with optional default value and bound checks. 00447 * Additional arguments are passed by value. 00448 */ 00449 PARSE_INT32 = 0x0001, 00450 PARSE_UINT32 = 0x0002, 00451 PARSE_DOUBLE = 0x0003, 00452 #if 0 /* not supported yet */ 00453 PARSE_INT16 = 0x0004, 00454 PARSE_UINT16 = 0x0005, 00455 #endif 00456 /* Returns a struct sockaddr_in, with optional default value 00457 * (passed by reference) and port handling (accept, ignore, 00458 * require, forbid). The format is 'host.name[:port]' 00459 */ 00460 PARSE_INADDR = 0x000f, 00461 00462 /* Other data types can be added as needed */ 00463 00464 /* If PARSE_DEFAULT is set, next argument is a default value 00465 * which is returned in case of error. The argument is passed 00466 * by value in case of numeric types, by reference in other cases. 00467 */ 00468 PARSE_DEFAULT = 0x0010, /* assign default on error */ 00469 00470 /* Request a range check, applicable to numbers. Two additional 00471 * arguments are passed by value, specifying the low-high end of 00472 * the range (inclusive). An error is returned if the value 00473 * is outside or inside the range, respectively. 00474 */ 00475 PARSE_IN_RANGE = 0x0020, /* accept values inside a range */ 00476 PARSE_OUT_RANGE = 0x0040, /* accept values outside a range */ 00477 00478 /* Port handling, for sockaddr_in. accept/ignore/require/forbid 00479 * port number after the hostname or address. 00480 */ 00481 PARSE_PORT_MASK = 0x0300, /* 0x000: accept port if present */ 00482 PARSE_PORT_IGNORE = 0x0100, /* 0x100: ignore port if present */ 00483 PARSE_PORT_REQUIRE = 0x0200, /* 0x200: require port number */ 00484 PARSE_PORT_FORBID = 0x0300, /* 0x100: forbid port number */ 00485 };
enum require_type |
Types used in ast_realtime_require_field.
RQ_INTEGER1 | |
RQ_UINTEGER1 | |
RQ_INTEGER2 | |
RQ_UINTEGER2 | |
RQ_INTEGER3 | |
RQ_UINTEGER3 | |
RQ_INTEGER4 | |
RQ_UINTEGER4 | |
RQ_INTEGER8 | |
RQ_UINTEGER8 | |
RQ_CHAR | |
RQ_FLOAT | |
RQ_DATE | |
RQ_DATETIME |
Definition at line 53 of file config.h.
00053 { 00054 RQ_INTEGER1, 00055 RQ_UINTEGER1, 00056 RQ_INTEGER2, 00057 RQ_UINTEGER2, 00058 RQ_INTEGER3, 00059 RQ_UINTEGER3, 00060 RQ_INTEGER4, 00061 RQ_UINTEGER4, 00062 RQ_INTEGER8, 00063 RQ_UINTEGER8, 00064 RQ_CHAR, 00065 RQ_FLOAT, 00066 RQ_DATE, 00067 RQ_DATETIME, 00068 } require_type;
void ast_category_append | ( | struct ast_config * | config, | |
struct ast_category * | cat | |||
) |
Definition at line 509 of file config.c.
References config, and ast_category::include_level.
Referenced by add_cfg_entry(), add_rt_multi_cfg_entry(), config_curl(), config_ldap(), config_odbc(), config_pgsql(), handle_updates(), process_text_line(), realtime_directory(), realtime_multi_curl(), realtime_multi_ldap(), realtime_multi_odbc(), and realtime_multi_pgsql().
00510 { 00511 if (config->last) 00512 config->last->next = category; 00513 else 00514 config->root = category; 00515 category->include_level = config->include_level; 00516 config->last = category; 00517 config->current = category; 00518 }
char* ast_category_browse | ( | struct ast_config * | config, | |
const char * | prev | |||
) |
Goes through categories.
config | Which config structure you wish to "browse" | |
prev | A pointer to a previous category. This function is kind of non-intuitive in it's use. To begin, one passes NULL as the second argument. 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. |
a | category on success | |
NULL | on failure/no-more-categories |
Definition at line 600 of file config.c.
References config, ast_category::name, ast_category::next, and next_available_category().
Referenced by __queues_show(), action_getconfig(), action_getconfigjson(), action_listcategories(), aji_load_config(), complete_sipnotify(), get_insecure_variable_from_config(), gtalk_load_config(), iax_provision_reload(), ind_load_module(), jingle_load_config(), load_config(), load_module(), load_moh_classes(), load_odbc_config(), misdn_cfg_init(), osp_load(), parse_config(), pbx_load_config(), pbx_load_users(), read_agent_config(), realtime_directory(), realtime_switch_common(), reload(), reload_config(), reload_followme(), reload_queue_rules(), reload_queues(), rpt_master(), search_directory(), set_config(), setup_dahdi(), show_users_realtime(), sla_load_config(), update_realtime_members(), and vm_change_password().
00601 { 00602 struct ast_category *cat = NULL; 00603 00604 if (prev && config->last_browse && (config->last_browse->name == prev)) 00605 cat = config->last_browse->next; 00606 else if (!prev && config->root) 00607 cat = config->root; 00608 else if (prev) { 00609 for (cat = config->root; cat; cat = cat->next) { 00610 if (cat->name == prev) { 00611 cat = cat->next; 00612 break; 00613 } 00614 } 00615 if (!cat) { 00616 for (cat = config->root; cat; cat = cat->next) { 00617 if (!strcasecmp(cat->name, prev)) { 00618 cat = cat->next; 00619 break; 00620 } 00621 } 00622 } 00623 } 00624 00625 if (cat) 00626 cat = next_available_category(cat); 00627 00628 config->last_browse = cat; 00629 return (cat) ? cat->name : NULL; 00630 }
int ast_category_delete | ( | struct ast_config * | cfg, | |
const char * | category | |||
) |
Definition at line 761 of file config.c.
References ast_category_destroy(), ast_config::last, ast_category::next, and ast_config::root.
Referenced by handle_updates().
00762 { 00763 struct ast_category *prev=NULL, *cat; 00764 00765 cat = cfg->root; 00766 while (cat) { 00767 if (cat->name == category) { 00768 if (prev) { 00769 prev->next = cat->next; 00770 if (cat == cfg->last) 00771 cfg->last = prev; 00772 } else { 00773 cfg->root = cat->next; 00774 if (cat == cfg->last) 00775 cfg->last = NULL; 00776 } 00777 ast_category_destroy(cat); 00778 return 0; 00779 } 00780 prev = cat; 00781 cat = cat->next; 00782 } 00783 00784 prev = NULL; 00785 cat = cfg->root; 00786 while (cat) { 00787 if (!strcasecmp(cat->name, category)) { 00788 if (prev) { 00789 prev->next = cat->next; 00790 if (cat == cfg->last) 00791 cfg->last = prev; 00792 } else { 00793 cfg->root = cat->next; 00794 if (cat == cfg->last) 00795 cfg->last = NULL; 00796 } 00797 ast_category_destroy(cat); 00798 return 0; 00799 } 00800 prev = cat; 00801 cat = cat->next; 00802 } 00803 return -1; 00804 }
void ast_category_destroy | ( | struct ast_category * | cat | ) |
Definition at line 548 of file config.c.
References ast_comment_destroy(), ast_destroy_template_list(), ast_free, ast_variables_destroy(), ast_category::file, free, ast_category::precomments, ast_category::root, ast_category::sameline, and ast_category::trailing.
Referenced by add_cfg_entry(), ast_category_delete(), ast_config_destroy(), process_text_line(), and realtime_multi_odbc().
00549 { 00550 ast_variables_destroy(cat->root); 00551 if (cat->file) { 00552 free(cat->file); 00553 cat->file = 0; 00554 } 00555 ast_comment_destroy(&cat->precomments); 00556 ast_comment_destroy(&cat->sameline); 00557 ast_comment_destroy(&cat->trailing); 00558 ast_destroy_template_list(cat); 00559 ast_free(cat); 00560 }
struct ast_variable* ast_category_detach_variables | ( | struct ast_category * | cat | ) |
Definition at line 632 of file config.c.
References ast_category::last, and ast_category::root.
Referenced by realtime_switch_common().
00633 { 00634 struct ast_variable *v; 00635 00636 v = cat->root; 00637 cat->root = NULL; 00638 cat->last = NULL; 00639 00640 return v; 00641 }
int ast_category_empty | ( | struct ast_config * | cfg, | |
const char * | category | |||
) |
Removes and destroys all variables within a category.
0 | if the category was found and emptied | |
-1 | if the category was not found |
Definition at line 806 of file config.c.
References ast_variables_destroy(), ast_category::last, ast_category::name, ast_category::next, ast_category::root, and ast_config::root.
Referenced by handle_updates().
00807 { 00808 struct ast_category *cat; 00809 00810 for (cat = cfg->root; cat; cat = cat->next) { 00811 if (!strcasecmp(cat->name, category)) 00812 continue; 00813 ast_variables_destroy(cat->root); 00814 cat->root = NULL; 00815 cat->last = NULL; 00816 return 0; 00817 } 00818 00819 return -1; 00820 }
int ast_category_exist | ( | const struct ast_config * | config, | |
const char * | category_name | |||
) |
Check for category duplicates.
config | which config to use | |
category_name | name of the category you're looking for This will search through the categories within a given config file for a match. |
Definition at line 504 of file config.c.
References ast_category_get(), and config.
00505 { 00506 return !!ast_category_get(config, category_name); 00507 }
struct ast_variable* ast_category_first | ( | struct ast_category * | cat | ) |
given a pointer to a category, return the root variable. This is equivalent to ast_variable_browse(), but more efficient if we already have the struct ast_category * (e.g. from ast_category_get())
return the first var of a category
Definition at line 586 of file config.c.
References ast_category::root.
Referenced by process_text_line().
struct ast_category* ast_category_get | ( | const struct ast_config * | config, | |
const char * | category_name | |||
) |
Retrieve a category if it exists.
config | which config to use | |
category_name | name of the category you're looking for This will search through the categories within a given config file for a match. |
pointer | to category if found | |
NULL | if not. |
Definition at line 499 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().
00500 { 00501 return category_get(config, category_name, 0); 00502 }
void ast_category_insert | ( | struct ast_config * | config, | |
struct ast_category * | cat, | |||
const char * | match | |||
) |
Inserts new category.
config | which config to use | |
cat | newly created category to insert | |
match | which category to insert above This function is used to insert a new category above another category matching the match parameter. |
Definition at line 520 of file config.c.
References config, ast_category::name, and ast_category::next.
Referenced by handle_updates().
00521 { 00522 struct ast_category *cur_category; 00523 00524 if (!cat || !match) 00525 return; 00526 if (!strcasecmp(config->root->name, match)) { 00527 cat->next = config->root; 00528 config->root = cat; 00529 return; 00530 } 00531 for (cur_category = config->root; cur_category; cur_category = cur_category->next) { 00532 if (!strcasecmp(cur_category->next->name, match)) { 00533 cat->next = cur_category->next; 00534 cur_category->next = cat; 00535 break; 00536 } 00537 } 00538 }
struct ast_category* ast_category_new | ( | const char * | name, | |
const char * | in_file, | |||
int | lineno | |||
) |
Create a category structure.
Definition at line 470 of file config.c.
References ast_calloc, ast_copy_string(), and strdup.
Referenced by add_cfg_entry(), add_rt_multi_cfg_entry(), config_curl(), config_ldap(), config_odbc(), config_pgsql(), handle_updates(), process_text_line(), realtime_directory(), realtime_multi_curl(), realtime_multi_ldap(), realtime_multi_odbc(), and realtime_multi_pgsql().
00471 { 00472 struct ast_category *category; 00473 00474 if ((category = ast_calloc(1, sizeof(*category)))) 00475 ast_copy_string(category->name, name, sizeof(category->name)); 00476 category->file = strdup(in_file); 00477 category->lineno = lineno; /* if you don't know the lineno, set it to 999999 or something real big */ 00478 return category; 00479 }
void ast_category_rename | ( | struct ast_category * | cat, | |
const char * | name | |||
) |
Definition at line 643 of file config.c.
References ast_copy_string(), and ast_category::name.
Referenced by handle_updates(), realtime_multi_curl(), realtime_multi_odbc(), and realtime_multi_pgsql().
00644 { 00645 ast_copy_string(cat->name, name, sizeof(cat->name)); 00646 }
struct ast_variable* ast_category_root | ( | struct ast_config * | config, | |
char * | cat | |||
) |
returns the root ast_variable of a config
config | pointer to an ast_config data structure | |
cat | name of the category for which you want the root |
Definition at line 591 of file config.c.
References ast_category_get(), config, and ast_category::root.
Referenced by get_insecure_variable_from_config().
00592 { 00593 struct ast_category *category = ast_category_get(config, cat); 00594 00595 if (category) 00596 return category->root; 00597 return NULL; 00598 }
int ast_check_realtime | ( | const char * | family | ) |
Check if realtime engine is configured for family.
family | which family/config to be checked |
Definition at line 2142 of file config.c.
References find_engine().
Referenced by __queues_show(), _sip_show_peer(), _sip_show_peers(), ast_queue_log(), copy_plain_file(), destroy_association(), handle_response_peerpoke(), handle_voicemail_show_users(), leave_voicemail(), load_module(), local_ast_moh_start(), realtime_peer(), realtime_update_peer(), rename_file(), sip_poke_noanswer(), sip_show_settings(), and vm_delete().
02143 { 02144 struct ast_config_engine *eng; 02145 02146 eng = find_engine(family, NULL, 0, NULL, 0); 02147 if (eng) 02148 return 1; 02149 return 0; 02150 }
void ast_config_destroy | ( | struct ast_config * | config | ) |
Destroys a config.
config | pointer to config data structure Free memory associated with a given config |
Definition at line 822 of file config.c.
References ast_category_destroy(), ast_free, ast_includes_destroy(), ast_config::includes, ast_category::next, and ast_config::root.
Referenced by __ast_http_post_load(), __ast_rtp_reload(), __ast_udptl_reload(), __queues_show(), _dsp_init(), action_getconfig(), action_listcategories(), action_updateconfig(), advanced_options(), aji_load_config(), ast_config_load2(), conf_exec(), config_function_read(), config_module(), directory_exec(), do_reload(), festival_exec(), find_conf(), handle_cli_dialplan_save(), iax_provision_reload(), ind_load_module(), init_logger_chain(), load_config(), load_config_meetme(), load_module(), load_realtime_queue(), load_rpt_vars(), make_email_file(), misdn_cfg_init(), node_lookup(), odbc_load_module(), osp_load(), parse_config(), pbx_load_users(), play_message(), prep_email_sub_vars(), private_enum_init(), read_agent_config(), read_config_maps(), realtime_directory(), realtime_multi_handler(), realtime_switch_common(), reload(), reload_config(), reload_followme(), rpt_master(), run_startup_commands(), set_config(), setup_dahdi(), show_users_realtime(), sla_load_config(), store_config(), tds_load_module(), unload_module(), update_realtime_members(), and vm_forwardoptions().
00823 { 00824 struct ast_category *cat, *catn; 00825 00826 if (!cfg) 00827 return; 00828 00829 ast_includes_destroy(cfg->includes); 00830 00831 cat = cfg->root; 00832 while (cat) { 00833 catn = cat; 00834 cat = cat->next; 00835 ast_category_destroy(catn); 00836 } 00837 ast_free(cfg); 00838 }
int ast_config_engine_deregister | ( | struct ast_config_engine * | del | ) |
Deregister config engine.
0 | Always |
Definition at line 1964 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().
01965 { 01966 struct ast_config_engine *ptr, *last=NULL; 01967 01968 ast_mutex_lock(&config_lock); 01969 01970 for (ptr = config_engine_list; ptr; ptr=ptr->next) { 01971 if (ptr == del) { 01972 if (last) 01973 last->next = ptr->next; 01974 else 01975 config_engine_list = ptr->next; 01976 break; 01977 } 01978 last = ptr; 01979 } 01980 01981 ast_mutex_unlock(&config_lock); 01982 01983 return 0; 01984 }
int ast_config_engine_register | ( | struct ast_config_engine * | newconfig | ) |
Register config engine.
1 | Always |
Definition at line 1945 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().
01946 { 01947 struct ast_config_engine *ptr; 01948 01949 ast_mutex_lock(&config_lock); 01950 01951 if (!config_engine_list) { 01952 config_engine_list = new; 01953 } else { 01954 for (ptr = config_engine_list; ptr->next; ptr=ptr->next); 01955 ptr->next = new; 01956 } 01957 01958 ast_mutex_unlock(&config_lock); 01959 ast_log(LOG_NOTICE,"Registered Config Engine %s\n", new->name); 01960 01961 return 1; 01962 }
struct ast_category* ast_config_get_current_category | ( | const struct ast_config * | cfg | ) |
Retrieve the current category name being built. API for backend configuration engines while building a configuration set.
Definition at line 840 of file config.c.
References ast_config::current.
Referenced by config_curl(), config_odbc(), and config_text_file_load().
00841 { 00842 return cfg->current; 00843 }
struct ast_config* ast_config_internal_load | ( | const char * | configfile, | |
struct ast_config * | cfg, | |||
struct ast_flags | flags, | |||
const char * | suggested_incl_file, | |||
const char * | who_asked | |||
) |
Definition at line 2026 of file config.c.
References ast_log(), config_engine_list, CONFIG_STATUS_FILEUNCHANGED, 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 add_cfg_entry(), ast_config_load2(), config_curl(), config_ldap(), config_odbc(), config_pgsql(), process_text_line(), and read_config_maps().
02027 { 02028 char db[256]; 02029 char table[256]; 02030 struct ast_config_engine *loader = &text_file_engine; 02031 struct ast_config *result; 02032 02033 /* The config file itself bumps include_level by 1 */ 02034 if (cfg->max_include_level > 0 && cfg->include_level == cfg->max_include_level + 1) { 02035 ast_log(LOG_WARNING, "Maximum Include level (%d) exceeded\n", cfg->max_include_level); 02036 return NULL; 02037 } 02038 02039 cfg->include_level++; 02040 02041 if (strcmp(filename, extconfig_conf) && strcmp(filename, "asterisk.conf") && config_engine_list) { 02042 struct ast_config_engine *eng; 02043 02044 eng = find_engine(filename, db, sizeof(db), table, sizeof(table)); 02045 02046 02047 if (eng && eng->load_func) { 02048 loader = eng; 02049 } else { 02050 eng = find_engine("global", db, sizeof(db), table, sizeof(table)); 02051 if (eng && eng->load_func) 02052 loader = eng; 02053 } 02054 } 02055 02056 result = loader->load_func(db, table, filename, cfg, flags, suggested_include_file, who_asked); 02057 02058 if (result && result != CONFIG_STATUS_FILEUNCHANGED) 02059 result->include_level--; 02060 else 02061 cfg->include_level--; 02062 02063 return result; 02064 }
struct ast_config* ast_config_load2 | ( | const char * | filename, | |
const char * | who_asked, | |||
struct ast_flags | flags | |||
) |
Load a config file.
filename | path of file to open. If no preceding '/' character, path is considered relative to AST_CONFIG_DIR Create a config structure from a given configuration file. | |
who_asked | The module which is making this request. | |
flags | Optional flags: CONFIG_FLAG_WITHCOMMENTS - load the file with comments intact; CONFIG_FLAG_FILEUNCHANGED - check the file mtime and return CONFIG_STATUS_FILEUNCHANGED if the mtime is the same; or CONFIG_FLAG_NOCACHE - don't cache file mtime (main purpose of this option is to save memory on temporary files). |
NULL | on error |
Definition at line 2066 of file config.c.
References ast_config_destroy(), ast_config_internal_load(), ast_config_new(), and CONFIG_STATUS_FILEUNCHANGED.
Referenced by __ast_http_load(), __ast_http_post_load(), __ast_rtp_reload(), __ast_udptl_reload(), __init_manager(), _dsp_init(), action_getconfig(), action_getconfigjson(), action_listcategories(), action_updateconfig(), ast_readconfig(), do_reload(), iax_provision_reload(), init_logger_chain(), load_config(), load_modules(), misdn_cfg_init(), private_enum_init(), and run_startup_commands().
02067 { 02068 struct ast_config *cfg; 02069 struct ast_config *result; 02070 02071 cfg = ast_config_new(); 02072 if (!cfg) 02073 return NULL; 02074 02075 result = ast_config_internal_load(filename, cfg, flags, "", who_asked); 02076 if (!result || result == CONFIG_STATUS_FILEUNCHANGED) 02077 ast_config_destroy(cfg); 02078 02079 return result; 02080 }
struct ast_config* ast_config_new | ( | void | ) |
Create a new base configuration structure.
Definition at line 660 of file config.c.
References ast_calloc, config, and MAX_INCLUDE_LEVEL.
Referenced by ast_config_load2(), read_config_maps(), realtime_multi_curl(), realtime_multi_handler(), realtime_multi_ldap(), realtime_multi_odbc(), and realtime_multi_pgsql().
00661 { 00662 struct ast_config *config; 00663 00664 if ((config = ast_calloc(1, sizeof(*config)))) 00665 config->max_include_level = MAX_INCLUDE_LEVEL; 00666 return config; 00667 }
const char* ast_config_option | ( | struct ast_config * | cfg, | |
const char * | cat, | |||
const char * | var | |||
) |
Retrieve a configuration variable within the configuration set. Retrieves the named variable var
within category cat
of configuration set cfg
. If not found, attempts to retrieve the named variable var
from within category general.
var
, or NULL if not found. Definition at line 416 of file config.c.
References ast_variable_retrieve().
Referenced by load_config(), pbx_load_users(), and search_directory().
00417 { 00418 const char *tmp; 00419 tmp = ast_variable_retrieve(cfg, cat, var); 00420 if (!tmp) 00421 tmp = ast_variable_retrieve(cfg, "general", var); 00422 return tmp; 00423 }
void ast_config_set_current_category | ( | struct ast_config * | cfg, | |
const struct ast_category * | cat | |||
) |
Set the category within the configuration as being current. API for backend configuration engines while building a configuration set.
Definition at line 845 of file config.c.
References ast_config::current.
00846 { 00847 /* cast below is just to silence compiler warning about dropping "const" */ 00848 cfg->current = (struct ast_category *) cat; 00849 }
int ast_destroy_realtime | ( | const char * | family, | |
const char * | keyfield, | |||
const char * | lookup, | |||
... | ||||
) |
Destroy realtime configuration.
family | which family/config to be destroyed | |
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 destroy an entry in realtime configuration space. Additional params are used as keys. |
Definition at line 2241 of file config.c.
References db, ast_config_engine::destroy_func, find_engine(), and table.
Referenced by function_realtime_readdestroy(), leave_voicemail(), and vm_delete().
02242 { 02243 struct ast_config_engine *eng; 02244 int res = -1; 02245 char db[256]=""; 02246 char table[256]=""; 02247 va_list ap; 02248 02249 va_start(ap, lookup); 02250 eng = find_engine(family, db, sizeof(db), table, sizeof(table)); 02251 if (eng && eng->destroy_func) 02252 res = eng->destroy_func(db, table, keyfield, lookup, ap); 02253 va_end(ap); 02254 02255 return res; 02256 }
struct ast_config_include* ast_include_find | ( | struct ast_config * | conf, | |
const char * | included_file | |||
) |
Definition at line 332 of file config.c.
References ast_config_include::included_file, ast_config::includes, and ast_config_include::next.
Referenced by ast_include_new().
00333 { 00334 struct ast_config_include *x; 00335 for (x=conf->includes;x;x=x->next) { 00336 if (strcmp(x->included_file,included_file) == 0) 00337 return x; 00338 } 00339 return 0; 00340 }
struct ast_config_include* ast_include_new | ( | struct ast_config * | conf, | |
const char * | from_file, | |||
const char * | included_file, | |||
int | is_exec, | |||
const char * | exec_file, | |||
int | from_lineno, | |||
char * | real_included_file_name, | |||
int | real_included_file_name_size | |||
) |
Definition at line 241 of file config.c.
References ast_calloc, ast_include_find(), ast_log(), ast_strdup, ast_strlen_zero(), ast_config::includes, and LOG_WARNING.
Referenced by process_text_line().
00242 { 00243 /* a file should be included ONCE. Otherwise, if one of the instances is changed, 00244 * then all be changed. -- how do we know to include it? -- Handling modified 00245 * instances is possible, I'd have 00246 * to create a new master for each instance. */ 00247 struct ast_config_include *inc; 00248 struct stat statbuf; 00249 00250 inc = ast_include_find(conf, included_file); 00251 if (inc) { 00252 do { 00253 inc->inclusion_count++; 00254 snprintf(real_included_file_name, real_included_file_name_size, "%s~~%d", included_file, inc->inclusion_count); 00255 } while (stat(real_included_file_name, &statbuf) == 0); 00256 ast_log(LOG_WARNING,"'%s', line %d: Same File included more than once! This data will be saved in %s if saved back to disk.\n", from_file, from_lineno, real_included_file_name); 00257 } else 00258 *real_included_file_name = 0; 00259 00260 inc = ast_calloc(1,sizeof(struct ast_config_include)); 00261 inc->include_location_file = ast_strdup(from_file); 00262 inc->include_location_lineno = from_lineno; 00263 if (!ast_strlen_zero(real_included_file_name)) 00264 inc->included_file = ast_strdup(real_included_file_name); 00265 else 00266 inc->included_file = ast_strdup(included_file); 00267 00268 inc->exec = is_exec; 00269 if (is_exec) 00270 inc->exec_file = ast_strdup(exec_file); 00271 00272 /* attach this new struct to the conf struct */ 00273 inc->next = conf->includes; 00274 conf->includes = inc; 00275 00276 return inc; 00277 }
void ast_include_rename | ( | struct ast_config * | conf, | |
const char * | from_file, | |||
const char * | to_file | |||
) |
Definition at line 279 of file config.c.
References ast_variable::file, ast_category::file, free, ast_config_include::include_location_file, ast_config::includes, ast_variable::next, ast_category::next, ast_config_include::next, ast_category::root, ast_config::root, and strdup.
Referenced by action_updateconfig().
00280 { 00281 struct ast_config_include *incl; 00282 struct ast_category *cat; 00283 struct ast_variable *v; 00284 00285 int from_len = strlen(from_file); 00286 int to_len = strlen(to_file); 00287 00288 if (strcmp(from_file, to_file) == 0) /* no use wasting time if the name is the same */ 00289 return; 00290 00291 /* the manager code allows you to read in one config file, then 00292 * write it back out under a different name. But, the new arrangement 00293 * ties output lines to the file name. So, before you try to write 00294 * the config file to disk, better riffle thru the data and make sure 00295 * the file names are changed. 00296 */ 00297 /* file names are on categories, includes (of course), and on variables. So, 00298 * traverse all this and swap names */ 00299 00300 for (incl = conf->includes; incl; incl=incl->next) { 00301 if (strcmp(incl->include_location_file,from_file) == 0) { 00302 if (from_len >= to_len) 00303 strcpy(incl->include_location_file, to_file); 00304 else { 00305 free(incl->include_location_file); 00306 incl->include_location_file = strdup(to_file); 00307 } 00308 } 00309 } 00310 for (cat = conf->root; cat; cat = cat->next) { 00311 if (strcmp(cat->file,from_file) == 0) { 00312 if (from_len >= to_len) 00313 strcpy(cat->file, to_file); 00314 else { 00315 free(cat->file); 00316 cat->file = strdup(to_file); 00317 } 00318 } 00319 for (v = cat->root; v; v = v->next) { 00320 if (strcmp(v->file,from_file) == 0) { 00321 if (from_len >= to_len) 00322 strcpy(v->file, to_file); 00323 else { 00324 free(v->file); 00325 v->file = strdup(to_file); 00326 } 00327 } 00328 } 00329 } 00330 }
struct ast_variable* ast_load_realtime | ( | const char * | family, | |
... | ||||
) |
Retrieve realtime configuration.
family | which family/config to lookup This will use builtin configuration backends to look up a particular entity in realtime and return a variable list of its parameters. Note that unlike the variables in ast_config, the resulting list of variables MUST be freed with ast_variables_destroy() as there is no container. |
Note that you should use the constant SENTINEL to terminate arguments, in order to preserve cross-platform compatibility.
Definition at line 2108 of file config.c.
References ast_free, ast_load_realtime_helper(), ast_strlen_zero(), ast_variable::next, and ast_variable::value.
Referenced by copy_plain_file(), find_conf_realtime(), find_user_realtime(), leave_queue(), load_realtime_queue(), local_ast_moh_start(), queue_function_queuewaitingcount(), realtime_alias(), realtime_peer(), realtime_switch_common(), and realtime_user().
02109 { 02110 struct ast_variable *res, *cur, *prev = NULL, *freeme = NULL; 02111 va_list ap; 02112 02113 va_start(ap, family); 02114 res = ast_load_realtime_helper(family, ap); 02115 va_end(ap); 02116 02117 /* Eliminate blank entries */ 02118 for (cur = res; cur; cur = cur->next) { 02119 if (freeme) { 02120 ast_free(freeme); 02121 freeme = NULL; 02122 } 02123 02124 if (ast_strlen_zero(cur->value)) { 02125 if (prev) 02126 prev->next = cur->next; 02127 else 02128 res = cur->next; 02129 freeme = cur; 02130 } else if (cur->value[0] == ' ' && cur->value[1] == '\0') { 02131 char *vptr = (char *) cur->value; 02132 vptr[0] = '\0'; 02133 prev = cur; 02134 } else { 02135 prev = cur; 02136 } 02137 } 02138 return res; 02139 }
struct ast_variable* ast_load_realtime_all | ( | const char * | family, | |
... | ||||
) |
Definition at line 2096 of file config.c.
References ast_load_realtime_helper().
Referenced by cli_realtime_load(), function_realtime_read(), and function_realtime_readdestroy().
02097 { 02098 struct ast_variable *res; 02099 va_list ap; 02100 02101 va_start(ap, family); 02102 res = ast_load_realtime_helper(family, ap); 02103 va_end(ap); 02104 02105 return res; 02106 }
struct ast_config* ast_load_realtime_multientry | ( | const char * | family, | |
... | ||||
) |
Retrieve realtime configuration.
family | which family/config to lookup This will use builtin configuration backends to look up a particular entity in realtime and return a variable list of its parameters. Unlike the ast_load_realtime, this function can return more than one entry and is thus stored inside a traditional ast_config structure rather than just returning a linked list of variables. |
Definition at line 2190 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(), show_users_realtime(), and update_realtime_members().
02191 { 02192 struct ast_config_engine *eng; 02193 char db[256]=""; 02194 char table[256]=""; 02195 struct ast_config *res=NULL; 02196 va_list ap; 02197 02198 va_start(ap, family); 02199 eng = find_engine(family, db, sizeof(db), table, sizeof(table)); 02200 if (eng && eng->realtime_multi_func) 02201 res = eng->realtime_multi_func(db, table, ap); 02202 va_end(ap); 02203 02204 return res; 02205 }
int ast_parse_arg | ( | const char * | arg, | |
enum ast_parse_flags | flags, | |||
void * | result, | |||
... | ||||
) |
The argument parsing routine.
arg | the string to parse. It is not modified. | |
flags | combination of ast_parse_flags to specify the return type and additional checks. | |
result | pointer to the result. NULL is valid here, and can be used to perform only the validity checks. | |
... | extra arguments are required according to flags. |
0 | in case of success, != 0 otherwise. | |
result | returns the parsed value in case of success, the default value in case of error, or it is left unchanged in case of error and no default specified. Note that in certain cases (e.g. sockaddr_in, with multi-field return values) some of the fields in result may be changed even if an error occurs. |
Definition at line 2261 of file config.c.
References ahp, ast_debug, ast_gethostbyname(), ast_inet_ntoa(), ast_strdupa, buf, hp, PARSE_DEFAULT, PARSE_DOUBLE, PARSE_IN_RANGE, PARSE_INADDR, PARSE_INT32, PARSE_OUT_RANGE, PARSE_PORT_FORBID, PARSE_PORT_IGNORE, PARSE_PORT_MASK, PARSE_PORT_REQUIRE, PARSE_TYPE, PARSE_UINT32, and strsep().
Referenced by ast_sip_ouraddrfor(), and check_via_response().
02263 { 02264 va_list ap; 02265 int error = 0; 02266 02267 va_start(ap, p_result); 02268 switch (flags & PARSE_TYPE) { 02269 case PARSE_INT32: 02270 { 02271 int32_t *result = p_result; 02272 int32_t x, def = result ? *result : 0, 02273 high = (int32_t)0x7fffffff, 02274 low = (int32_t)0x80000000; 02275 /* optional argument: first default value, then range */ 02276 if (flags & PARSE_DEFAULT) 02277 def = va_arg(ap, int32_t); 02278 if (flags & (PARSE_IN_RANGE|PARSE_OUT_RANGE)) { 02279 /* range requested, update bounds */ 02280 low = va_arg(ap, int32_t); 02281 high = va_arg(ap, int32_t); 02282 } 02283 x = strtol(arg, NULL, 0); 02284 error = (x < low) || (x > high); 02285 if (flags & PARSE_OUT_RANGE) 02286 error = !error; 02287 if (result) 02288 *result = error ? def : x; 02289 ast_debug(3, 02290 "extract int from [%s] in [%d, %d] gives [%d](%d)\n", 02291 arg, low, high, 02292 result ? *result : x, error); 02293 break; 02294 } 02295 02296 case PARSE_UINT32: 02297 { 02298 uint32_t *result = p_result; 02299 uint32_t x, def = result ? *result : 0, 02300 low = 0, high = (uint32_t)~0; 02301 /* optional argument: first default value, then range */ 02302 if (flags & PARSE_DEFAULT) 02303 def = va_arg(ap, uint32_t); 02304 if (flags & (PARSE_IN_RANGE|PARSE_OUT_RANGE)) { 02305 /* range requested, update bounds */ 02306 low = va_arg(ap, uint32_t); 02307 high = va_arg(ap, uint32_t); 02308 } 02309 x = strtoul(arg, NULL, 0); 02310 error = (x < low) || (x > high); 02311 if (flags & PARSE_OUT_RANGE) 02312 error = !error; 02313 if (result) 02314 *result = error ? def : x; 02315 ast_debug(3, 02316 "extract uint from [%s] in [%u, %u] gives [%u](%d)\n", 02317 arg, low, high, 02318 result ? *result : x, error); 02319 break; 02320 } 02321 02322 case PARSE_DOUBLE: 02323 { 02324 double *result = p_result; 02325 double x, def = result ? *result : 0, 02326 low = -HUGE_VAL, high = HUGE_VAL; 02327 02328 /* optional argument: first default value, then range */ 02329 if (flags & PARSE_DEFAULT) 02330 def = va_arg(ap, double); 02331 if (flags & (PARSE_IN_RANGE|PARSE_OUT_RANGE)) { 02332 /* range requested, update bounds */ 02333 low = va_arg(ap, double); 02334 high = va_arg(ap, double); 02335 } 02336 x = strtod(arg, NULL); 02337 error = (x < low) || (x > high); 02338 if (flags & PARSE_OUT_RANGE) 02339 error = !error; 02340 if (result) 02341 *result = error ? def : x; 02342 ast_debug(3, 02343 "extract double from [%s] in [%f, %f] gives [%f](%d)\n", 02344 arg, low, high, 02345 result ? *result : x, error); 02346 break; 02347 } 02348 case PARSE_INADDR: 02349 { 02350 char *port, *buf; 02351 struct sockaddr_in _sa_buf; /* buffer for the result */ 02352 struct sockaddr_in *sa = p_result ? 02353 (struct sockaddr_in *)p_result : &_sa_buf; 02354 /* default is either the supplied value or the result itself */ 02355 struct sockaddr_in *def = (flags & PARSE_DEFAULT) ? 02356 va_arg(ap, struct sockaddr_in *) : sa; 02357 struct hostent *hp; 02358 struct ast_hostent ahp; 02359 02360 memset(&_sa_buf, '\0', sizeof(_sa_buf)); /* clear buffer */ 02361 /* duplicate the string to strip away the :port */ 02362 port = ast_strdupa(arg); 02363 buf = strsep(&port, ":"); 02364 sa->sin_family = AF_INET; /* assign family */ 02365 /* 02366 * honor the ports flag setting, assign default value 02367 * in case of errors or field unset. 02368 */ 02369 flags &= PARSE_PORT_MASK; /* the only flags left to process */ 02370 if (port) { 02371 if (flags == PARSE_PORT_FORBID) { 02372 error = 1; /* port was forbidden */ 02373 sa->sin_port = def->sin_port; 02374 } else if (flags == PARSE_PORT_IGNORE) 02375 sa->sin_port = def->sin_port; 02376 else /* accept or require */ 02377 sa->sin_port = htons(strtol(port, NULL, 0)); 02378 } else { 02379 sa->sin_port = def->sin_port; 02380 if (flags == PARSE_PORT_REQUIRE) 02381 error = 1; 02382 } 02383 /* Now deal with host part, even if we have errors before. */ 02384 hp = ast_gethostbyname(buf, &ahp); 02385 if (hp) /* resolved successfully */ 02386 memcpy(&sa->sin_addr, hp->h_addr, sizeof(sa->sin_addr)); 02387 else { 02388 error = 1; 02389 sa->sin_addr = def->sin_addr; 02390 } 02391 ast_debug(3, 02392 "extract inaddr from [%s] gives [%s:%d](%d)\n", 02393 arg, ast_inet_ntoa(sa->sin_addr), 02394 ntohs(sa->sin_port), error); 02395 break; 02396 } 02397 } 02398 va_end(ap); 02399 return error; 02400 }
int ast_realtime_enabled | ( | void | ) |
Check if there's any realtime engines loaded.
Definition at line 2153 of file config.c.
References config_maps.
Referenced by action_coresettings(), and handle_show_settings().
02154 { 02155 return config_maps ? 1 : 0; 02156 }
int ast_realtime_require_field | ( | const char * | family, | |
... | ||||
) |
Inform realtime what fields that may be stored.
family | which family/config is referenced This will inform builtin configuration backends that particular fields may be updated during the use of that configuration section. This is mainly to be used during startup routines, to ensure that various fields exist in the backend. The backends may take various actions, such as creating new fields in the data store or warning the administrator that new fields may need to be created, in order to ensure proper function. |
A family should always specify its fields to the minimum necessary requirements to fulfill all possible values (within reason; for example, a timeout value may reasonably be specified as an INTEGER2, with size 5. Even though values above 32767 seconds are possible, they are unlikely to be useful, and we should not complain about that size).
0 | Required fields met specified standards | |
-1 | One or more fields was missing or insufficient |
Definition at line 2158 of file config.c.
References db, find_engine(), ast_config_engine::require_func, and table.
Referenced by change_password_realtime(), conf_run(), and load_module().
02159 { 02160 struct ast_config_engine *eng; 02161 char db[256] = ""; 02162 char table[256] = ""; 02163 va_list ap; 02164 int res = -1; 02165 02166 va_start(ap, family); 02167 eng = find_engine(family, db, sizeof(db), table, sizeof(table)); 02168 if (eng && eng->require_func) { 02169 res = eng->require_func(db, table, ap); 02170 } 02171 va_end(ap); 02172 02173 return res; 02174 }
int ast_rq_is_int | ( | require_type | type | ) | [inline] |
Check if require type is an integer type.
Definition at line 578 of file config.h.
Referenced by realtime_require_handler(), require_odbc(), and require_pgsql().
int ast_store_realtime | ( | const char * | family, | |
... | ||||
) |
Create realtime configuration.
family | which family/config to be created This function is used to create a parameter in realtime configuration space. |
Definition at line 2224 of file config.c.
References db, find_engine(), ast_config_engine::store_func, and table.
Referenced by ast_queue_log(), function_realtime_store(), and leave_voicemail().
02225 { 02226 struct ast_config_engine *eng; 02227 int res = -1; 02228 char db[256]=""; 02229 char table[256]=""; 02230 va_list ap; 02231 02232 va_start(ap, family); 02233 eng = find_engine(family, db, sizeof(db), table, sizeof(table)); 02234 if (eng && eng->store_func) 02235 res = eng->store_func(db, table, ap); 02236 va_end(ap); 02237 02238 return res; 02239 }
int ast_unload_realtime | ( | const char * | family | ) |
Release any resources cached for a realtime family.
family | which family/config to destroy Various backends may cache attributes about a realtime data storage facility; on reload, a front end resource may request to purge that cache. |
0 | If any cache was purged | |
-1 | If no cache was found |
Definition at line 2176 of file config.c.
References db, find_engine(), table, and ast_config_engine::unload_func.
Referenced by __unload_module(), load_config(), reload(), reload_config(), and unload_module().
02177 { 02178 struct ast_config_engine *eng; 02179 char db[256] = ""; 02180 char table[256] = ""; 02181 int res = -1; 02182 02183 eng = find_engine(family, db, sizeof(db), table, sizeof(table)); 02184 if (eng && eng->unload_func) { 02185 res = eng->unload_func(db, table); 02186 } 02187 return res; 02188 }
int ast_update_realtime | ( | const char * | family, | |
const char * | keyfield, | |||
const char * | lookup, | |||
... | ||||
) |
Update realtime configuration.
family | which family/config to be updated | |
keyfield | which field to use as the key | |
lookup | which value to look for in the key field to match the entry. This function is used to update a parameter in realtime configuration space. |
Definition at line 2207 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(), leave_voicemail(), realtime_update_peer(), rename_file(), sip_poke_noanswer(), and update_realtime_member_field().
02208 { 02209 struct ast_config_engine *eng; 02210 int res = -1; 02211 char db[256]=""; 02212 char table[256]=""; 02213 va_list ap; 02214 02215 va_start(ap, lookup); 02216 eng = find_engine(family, db, sizeof(db), table, sizeof(table)); 02217 if (eng && eng->update_func) 02218 res = eng->update_func(db, table, keyfield, lookup, ap); 02219 va_end(ap); 02220 02221 return res; 02222 }
void ast_variable_append | ( | struct ast_category * | category, | |
struct ast_variable * | variable | |||
) |
Definition at line 343 of file config.c.
References ast_category::last, ast_variable::next, and ast_category::root.
Referenced by add_cfg_entry(), add_rt_multi_cfg_entry(), config_curl(), config_ldap(), config_odbc(), config_pgsql(), handle_updates(), inherit_category(), move_variables(), process_text_line(), realtime_directory(), realtime_multi_curl(), realtime_multi_ldap(), realtime_multi_odbc(), realtime_multi_pgsql(), and vm_change_password().
00344 { 00345 if (!variable) 00346 return; 00347 if (category->last) 00348 category->last->next = variable; 00349 else 00350 category->root = variable; 00351 category->last = variable; 00352 while (category->last->next) 00353 category->last = category->last->next; 00354 }
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.
ast_variable | list on success | |
NULL | on failure |
Definition at line 404 of file config.c.
References ast_category_get(), config, and ast_category::root.
Referenced by __ast_http_load(), __ast_http_post_load(), __init_manager(), action_getconfig(), action_getconfigjson(), adsi_load(), aji_load_config(), ast_readconfig(), ast_variable_retrieve(), build_device(), check_tx_freq(), collect_function_digits(), conf_exec(), config_module(), do_say(), do_scheduler(), find_conf(), gtalk_load_config(), handle_cli_dialplan_save(), iax_template_parse(), ind_load_module(), init_logger_chain(), jingle_load_config(), load_config(), load_module(), load_modules(), load_moh_classes(), load_odbc_config(), load_rpt_vars(), misdn_cfg_init(), node_lookup(), odbc_load_module(), osp_create_provider(), parse_config(), pbx_load_config(), read_agent_config(), read_config_maps(), reload(), reload_config(), reload_followme(), reload_queue_rules(), reload_queues(), run_startup_commands(), search_directory(), set_config(), setup_dahdi(), show_users_realtime(), sip_cli_notify(), sla_build_station(), sla_build_trunk(), smdi_load(), store_config(), and tds_load_module().
00405 { 00406 struct ast_category *cat = NULL; 00407 00408 if (category && config->last_browse && (config->last_browse->name == category)) 00409 cat = config->last_browse; 00410 else 00411 cat = ast_category_get(config, category); 00412 00413 return (cat) ? cat->root : NULL; 00414 }
int ast_variable_delete | ( | struct ast_category * | category, | |
const char * | variable, | |||
const char * | match, | |||
const char * | line | |||
) |
Definition at line 669 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().
00670 { 00671 struct ast_variable *cur, *prev=NULL, *curn; 00672 int res = -1; 00673 int lineno = 0; 00674 00675 cur = category->root; 00676 while (cur) { 00677 if (cur->name == variable) { 00678 if (prev) { 00679 prev->next = cur->next; 00680 if (cur == category->last) 00681 category->last = prev; 00682 } else { 00683 category->root = cur->next; 00684 if (cur == category->last) 00685 category->last = NULL; 00686 } 00687 cur->next = NULL; 00688 ast_variables_destroy(cur); 00689 return 0; 00690 } 00691 prev = cur; 00692 cur = cur->next; 00693 } 00694 00695 prev = NULL; 00696 cur = category->root; 00697 while (cur) { 00698 curn = cur->next; 00699 if ((!ast_strlen_zero(line) && lineno == atoi(line)) || (ast_strlen_zero(line) && !strcasecmp(cur->name, variable) && (ast_strlen_zero(match) || !strcasecmp(cur->value, match)))) { 00700 if (prev) { 00701 prev->next = cur->next; 00702 if (cur == category->last) 00703 category->last = prev; 00704 } else { 00705 category->root = cur->next; 00706 if (cur == category->last) 00707 category->last = NULL; 00708 } 00709 cur->next = NULL; 00710 ast_variables_destroy(cur); 00711 res = 0; 00712 } else 00713 prev = cur; 00714 00715 cur = curn; 00716 lineno++; 00717 } 00718 return res; 00719 }
void ast_variable_insert | ( | struct ast_category * | category, | |
struct ast_variable * | variable, | |||
const char * | line | |||
) |
Definition at line 356 of file config.c.
References ast_variable::next, and ast_category::root.
Referenced by handle_updates().
00357 { 00358 struct ast_variable *cur = category->root; 00359 int lineno; 00360 int insertline; 00361 00362 if (!variable || sscanf(line, "%30d", &insertline) != 1) 00363 return; 00364 if (!insertline) { 00365 variable->next = category->root; 00366 category->root = variable; 00367 } else { 00368 for (lineno = 1; lineno < insertline; lineno++) { 00369 cur = cur->next; 00370 if (!cur->next) 00371 break; 00372 } 00373 variable->next = cur->next; 00374 cur->next = variable; 00375 } 00376 }
struct ast_variable* ast_variable_new | ( | const char * | name, | |
const char * | value, | |||
const char * | filename | |||
) |
Definition at line 218 of file config.c.
References __ast_calloc(), ast_calloc, and ast_variable::stuff.
Referenced by add_cfg_entry(), add_rt_cfg_entry(), add_rt_multi_cfg_entry(), add_var(), apply_outgoing(), ast_channeltype_list(), ast_variable_update(), astman_get_variables(), build_user(), check_access(), config_curl(), config_ldap(), config_odbc(), config_pgsql(), copy_vars(), create_vmaccount(), handle_updates(), handle_uri(), httpd_helper_thread(), iax_parse_ies(), ldap_table_config_add_attribute(), parkandannounce_exec(), parse_cookies(), process_text_line(), realtime_curl(), realtime_directory(), realtime_ldap_entry_to_var(), realtime_ldap_result_to_vars(), realtime_multi_curl(), realtime_multi_odbc(), realtime_multi_pgsql(), realtime_odbc(), realtime_pgsql(), transmit_notify_custom(), variable_clone(), and vm_change_password().
00220 { 00221 struct ast_variable *variable; 00222 int name_len = strlen(name) + 1; 00223 int val_len = strlen(value) + 1; 00224 int fn_len = strlen(filename) + 1; 00225 00226 #ifdef MALLOC_DEBUG 00227 if ((variable = __ast_calloc(1, name_len + val_len + fn_len + sizeof(*variable), file, lineno, func))) { 00228 #else 00229 if ((variable = ast_calloc(1, name_len + val_len + fn_len + sizeof(*variable)))) { 00230 #endif 00231 char *dst = variable->stuff; /* writable space starts here */ 00232 variable->name = strcpy(dst, name); 00233 dst += name_len; 00234 variable->value = strcpy(dst, value); 00235 dst += val_len; 00236 variable->file = strcpy(dst, filename); 00237 } 00238 return variable; 00239 }
const char* ast_variable_retrieve | ( | const struct ast_config * | config, | |
const char * | category, | |||
const char * | variable | |||
) |
Gets a variable.
config | which (opened) config to use | |
category | category under which the variable lies | |
variable | which variable you wish to get the data for Goes through a given config file in the given category and searches for the given variable |
The | variable value on success | |
NULL | if unable to find it. |
Definition at line 426 of file config.c.
References ast_variable_browse(), config, ast_variable::name, ast_category::next, ast_variable::next, ast_category::root, and ast_variable::value.
Referenced by __ast_rtp_reload(), __ast_udptl_reload(), _dsp_init(), advanced_options(), aji_load_config(), ast_config_option(), build_extension(), config_function_read(), config_module(), directory_exec(), do_reload(), do_scheduler(), festival_exec(), function_macro(), get_insecure_variable_from_config(), get_wait_interval(), gtalk_load_config(), iax_template_parse(), ind_load_module(), init_acf_query(), init_logger_chain(), jingle_load_config(), load_config(), load_config_meetme(), load_module(), load_rpt_vars(), make_email_file(), node_lookup(), odbc_load_module(), osp_load(), parse_config(), pbx_load_config(), pbx_load_users(), play_message(), prep_email_sub_vars(), private_enum_init(), read_agent_config(), realtime_directory(), reload_config(), reload_followme(), reload_queues(), retreive_memory(), retrieve_astcfgint(), rpt(), rpt_master(), rpt_tele_thread(), rpt_telemetry(), saynode(), search_directory(), 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().
00427 { 00428 struct ast_variable *v; 00429 00430 if (category) { 00431 for (v = ast_variable_browse(config, category); v; v = v->next) { 00432 if (!strcasecmp(variable, v->name)) 00433 return v->value; 00434 } 00435 } else { 00436 struct ast_category *cat; 00437 00438 for (cat = config->root; cat; cat = cat->next) 00439 for (v = cat->root; v; v = v->next) 00440 if (!strcasecmp(variable, v->name)) 00441 return v->value; 00442 } 00443 00444 return NULL; 00445 }
int ast_variable_update | ( | struct ast_category * | category, | |
const char * | variable, | |||
const char * | value, | |||
const char * | match, | |||
unsigned int | object | |||
) |
Update variable value within a config.
category | Category element within the config | |
variable | Name of the variable to change | |
value | New value of the variable | |
match | If set, previous value of the variable (if NULL or zero-length, no matching will be done) | |
object | Boolean of whether to make the new variable an object |
Definition at line 721 of file config.c.
References ast_strlen_zero(), ast_variable_new(), ast_variables_destroy(), ast_variable::blanklines, ast_variable::file, ast_category::last, ast_variable::lineno, ast_variable::name, ast_variable::next, ast_variable::object, ast_variable::precomments, ast_category::root, ast_variable::sameline, ast_variable::trailing, and ast_variable::value.
Referenced by handle_updates(), process_text_line(), vm_change_password(), and vm_forwardoptions().
00723 { 00724 struct ast_variable *cur, *prev=NULL, *newer=NULL; 00725 00726 for (cur = category->root; cur; prev = cur, cur = cur->next) { 00727 if (strcasecmp(cur->name, variable) || 00728 (!ast_strlen_zero(match) && strcasecmp(cur->value, match))) 00729 continue; 00730 00731 if (!(newer = ast_variable_new(variable, value, cur->file))) 00732 return -1; 00733 00734 newer->next = cur->next; 00735 newer->object = cur->object || object; 00736 00737 /* Preserve everything */ 00738 newer->lineno = cur->lineno; 00739 newer->blanklines = cur->blanklines; 00740 newer->precomments = cur->precomments; cur->precomments = NULL; 00741 newer->sameline = cur->sameline; cur->sameline = NULL; 00742 newer->trailing = cur->trailing; cur->trailing = NULL; 00743 00744 if (prev) 00745 prev->next = newer; 00746 else 00747 category->root = newer; 00748 if (category->last == cur) 00749 category->last = newer; 00750 00751 cur->next = NULL; 00752 ast_variables_destroy(cur); 00753 00754 return 0; 00755 } 00756 00757 /* Could not find variable to update */ 00758 return -1; 00759 }
void ast_variables_destroy | ( | struct ast_variable * | var | ) |
Free variable list.
var | the linked list of variables to free This function frees a list of variables. |
Definition at line 390 of file config.c.
References ast_comment_destroy(), ast_free, ast_variable::next, ast_variable::precomments, ast_variable::sameline, and ast_variable::trailing.
Referenced by __sip_destroy(), ast_category_destroy(), ast_category_empty(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_variable_delete(), ast_variable_update(), build_peer(), build_user(), cli_realtime_load(), destroy_dahdi_pvt(), find_conf_realtime(), find_user_realtime(), free_outgoing(), free_user(), function_realtime_read(), function_realtime_readdestroy(), handle_uri(), httpd_helper_thread(), ldap_loadentry(), leave_queue(), load_realtime_queue(), local_ast_moh_start(), manager_sipnotify(), pvt_destructor(), queue_function_queuewaitingcount(), realtime_alias(), realtime_canmatch(), realtime_exists(), realtime_handler(), realtime_ldap_base_ap(), realtime_ldap_result_to_vars(), realtime_matchmore(), realtime_odbc(), realtime_peer(), realtime_user(), sip_alloc(), sip_destroy_peer(), socket_process(), table_configs_free(), and user_destructor().
00391 { 00392 struct ast_variable *vn; 00393 00394 while (v) { 00395 vn = v; 00396 v = v->next; 00397 ast_comment_destroy(&vn->precomments); 00398 ast_comment_destroy(&vn->sameline); 00399 ast_comment_destroy(&vn->trailing); 00400 ast_free(vn); 00401 } 00402 }
int config_text_file_save | ( | const char * | filename, | |
const struct ast_config * | cfg, | |||
const char * | generator | |||
) |
Definition at line 1586 of file config.c.
References ao2_container_alloc, ao2_ref, ast_debug, AST_LIST_EMPTY, AST_LIST_LAST, AST_LIST_TRAVERSE, ast_verb, ast_comment::cmt, errno, ast_config_include::exec, ast_config_include::exec_file, f, ast_category::file, gen_header(), hash_string(), hashtab_compare_strings(), ast_category::ignored, ast_config_include::include_location_file, ast_config_include::include_location_lineno, ast_config_include::included_file, ast_config::includes, insert_leading_blank_lines(), ast_category_template_instance::inst, ast_category::lineno, ast_variable::name, ast_category_template_instance::name, ast_category::name, ast_category::next, ast_variable::next, cache_file_include::next, ast_comment::next, ast_config_include::next, option_debug, ast_config_include::output, ast_category::precomments, ast_category::root, ast_config::root, ast_category::sameline, set_fn(), ast_category::template_instances, ast_category::trailing, ast_variable::value, and var.
Referenced by action_updateconfig(), vm_change_password(), and vm_forwardoptions().
01587 { 01588 FILE *f; 01589 char fn[256]; 01590 struct ast_variable *var; 01591 struct ast_category *cat; 01592 struct ast_comment *cmt; 01593 struct ast_config_include *incl; 01594 int blanklines = 0; 01595 struct ao2_container *fileset = ao2_container_alloc(180000, hash_string, hashtab_compare_strings); 01596 struct inclfile *fi = 0; 01597 01598 /* reset all the output flags, in case this isn't our first time saving this data */ 01599 01600 for (incl=cfg->includes; incl; incl = incl->next) 01601 incl->output = 0; 01602 01603 /* go thru all the inclusions and make sure all the files involved (configfile plus all its inclusions) 01604 are all truncated to zero bytes and have that nice header*/ 01605 01606 for (incl=cfg->includes; incl; incl = incl->next) 01607 { 01608 if (!incl->exec) { /* leave the execs alone -- we'll write out the #exec directives, but won't zero out the include files or exec files*/ 01609 FILE *f1; 01610 01611 set_fn(fn, sizeof(fn), incl->included_file, configfile, fileset, &fi); /* normally, fn is just set to incl->included_file, prepended with config dir if relative */ 01612 f1 = fopen(fn,"w"); 01613 if (f1) { 01614 gen_header(f1, configfile, fn, generator); 01615 fclose(f1); /* this should zero out the file */ 01616 } else { 01617 ast_debug(1, "Unable to open for writing: %s\n", fn); 01618 ast_verb(2, "Unable to write %s (%s)", fn, strerror(errno)); 01619 } 01620 ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */ 01621 fi = 0; 01622 } 01623 } 01624 01625 set_fn(fn, sizeof(fn), 0, configfile, fileset, &fi); /* just set fn to absolute ver of configfile */ 01626 #ifdef __CYGWIN__ 01627 if ((f = fopen(fn, "w+"))) { 01628 #else 01629 if ((f = fopen(fn, "w"))) { 01630 #endif 01631 ast_verb(2, "Saving '%s': ", fn); 01632 gen_header(f, configfile, fn, generator); 01633 cat = cfg->root; 01634 fclose(f); 01635 ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */ 01636 01637 /* from here out, we open each involved file and concat the stuff we need to add to the end and immediately close... */ 01638 /* since each var, cat, and associated comments can come from any file, we have to be 01639 mobile, and open each file, print, and close it on an entry-by-entry basis */ 01640 01641 while (cat) { 01642 set_fn(fn, sizeof(fn), cat->file, configfile, fileset, &fi); 01643 f = fopen(fn, "a"); 01644 if (!f) 01645 { 01646 ast_debug(1, "Unable to open for writing: %s\n", fn); 01647 ast_verb(2, "Unable to write %s (%s)", fn, strerror(errno)); 01648 ao2_ref(fileset, -1); 01649 return -1; 01650 } 01651 01652 /* dump any includes that happen before this category header */ 01653 for (incl=cfg->includes; incl; incl = incl->next) { 01654 if (strcmp(incl->include_location_file, cat->file) == 0){ 01655 if (cat->lineno > incl->include_location_lineno && !incl->output) { 01656 if (incl->exec) 01657 fprintf(f,"#exec \"%s\"\n", incl->exec_file); 01658 else 01659 fprintf(f,"#include \"%s\"\n", incl->included_file); 01660 incl->output = 1; 01661 } 01662 } 01663 } 01664 01665 insert_leading_blank_lines(f, fi, cat->precomments, cat->lineno); 01666 /* Dump section with any appropriate comment */ 01667 for (cmt = cat->precomments; cmt; cmt=cmt->next) { 01668 char *cmtp = cmt->cmt; 01669 while (*cmtp == ';' && *(cmtp+1) == '!') { 01670 char *cmtp2 = strchr(cmtp+1, '\n'); 01671 if (cmtp2) 01672 cmtp = cmtp2+1; 01673 else cmtp = 0; 01674 } 01675 if (cmtp) 01676 fprintf(f,"%s", cmtp); 01677 } 01678 fprintf(f, "[%s]", cat->name); 01679 if (cat->ignored || !AST_LIST_EMPTY(&cat->template_instances)) { 01680 fprintf(f, "("); 01681 if (cat->ignored) { 01682 fprintf(f, "!"); 01683 } 01684 if (cat->ignored && !AST_LIST_EMPTY(&cat->template_instances)) { 01685 fprintf(f, ","); 01686 } 01687 if (!AST_LIST_EMPTY(&cat->template_instances)) { 01688 struct ast_category_template_instance *x; 01689 AST_LIST_TRAVERSE(&cat->template_instances, x, next) { 01690 fprintf(f,"%s",x->name); 01691 if (x != AST_LIST_LAST(&cat->template_instances)) 01692 fprintf(f,","); 01693 } 01694 } 01695 fprintf(f, ")"); 01696 } 01697 for(cmt = cat->sameline; cmt; cmt=cmt->next) 01698 { 01699 fprintf(f,"%s", cmt->cmt); 01700 } 01701 if (!cat->sameline) 01702 fprintf(f,"\n"); 01703 for (cmt = cat->trailing; cmt; cmt=cmt->next) { 01704 if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!') 01705 fprintf(f,"%s", cmt->cmt); 01706 } 01707 fclose(f); 01708 ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */ 01709 fi = 0; 01710 01711 var = cat->root; 01712 while (var) { 01713 struct ast_category_template_instance *x; 01714 int found = 0; 01715 AST_LIST_TRAVERSE(&cat->template_instances, x, next) { 01716 struct ast_variable *v; 01717 for (v = x->inst->root; v; v = v->next) { 01718 if (!strcasecmp(var->name, v->name) && !strcmp(var->value, v->value)) { 01719 found = 1; 01720 break; 01721 } 01722 } 01723 if (found) 01724 break; 01725 } 01726 if (found) { 01727 var = var->next; 01728 continue; 01729 } 01730 set_fn(fn, sizeof(fn), var->file, configfile, fileset, &fi); 01731 f = fopen(fn, "a"); 01732 if (!f) 01733 { 01734 ast_debug(1, "Unable to open for writing: %s\n", fn); 01735 ast_verb(2, "Unable to write %s (%s)", fn, strerror(errno)); 01736 ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */ 01737 fi = 0; 01738 ao2_ref(fileset, -1); 01739 return -1; 01740 } 01741 01742 /* dump any includes that happen before this category header */ 01743 for (incl=cfg->includes; incl; incl = incl->next) { 01744 if (strcmp(incl->include_location_file, var->file) == 0){ 01745 if (var->lineno > incl->include_location_lineno && !incl->output) { 01746 if (incl->exec) 01747 fprintf(f,"#exec \"%s\"\n", incl->exec_file); 01748 else 01749 fprintf(f,"#include \"%s\"\n", incl->included_file); 01750 incl->output = 1; 01751 } 01752 } 01753 } 01754 01755 insert_leading_blank_lines(f, fi, var->precomments, var->lineno); 01756 for (cmt = var->precomments; cmt; cmt=cmt->next) { 01757 if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!') 01758 fprintf(f,"%s", cmt->cmt); 01759 } 01760 if (var->sameline) 01761 fprintf(f, "%s %s %s %s", var->name, (var->object ? "=>" : "="), var->value, var->sameline->cmt); 01762 else 01763 fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="), var->value); 01764 for (cmt = var->trailing; cmt; cmt=cmt->next) { 01765 if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!') 01766 fprintf(f,"%s", cmt->cmt); 01767 } 01768 if (var->blanklines) { 01769 blanklines = var->blanklines; 01770 while (blanklines--) 01771 fprintf(f, "\n"); 01772 } 01773 01774 fclose(f); 01775 ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */ 01776 fi = 0; 01777 01778 var = var->next; 01779 } 01780 cat = cat->next; 01781 } 01782 if (!option_debug) 01783 ast_verb(2, "Saved\n"); 01784 } else { 01785 ast_debug(1, "Unable to open for writing: %s\n", fn); 01786 ast_verb(2, "Unable to write (%s)", strerror(errno)); 01787 ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */ 01788 ao2_ref(fileset, -1); 01789 return -1; 01790 } 01791 01792 /* Now, for files with trailing #include/#exec statements, 01793 we have to make sure every entry is output */ 01794 01795 for (incl=cfg->includes; incl; incl = incl->next) { 01796 if (!incl->output) { 01797 /* open the respective file */ 01798 set_fn(fn, sizeof(fn), incl->include_location_file, configfile, fileset, &fi); 01799 f = fopen(fn, "a"); 01800 if (!f) 01801 { 01802 ast_debug(1, "Unable to open for writing: %s\n", fn); 01803 ast_verb(2, "Unable to write %s (%s)", fn, strerror(errno)); 01804 ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */ 01805 fi = 0; 01806 ao2_ref(fileset, -1); 01807 return -1; 01808 } 01809 01810 /* output the respective include */ 01811 if (incl->exec) 01812 fprintf(f,"#exec \"%s\"\n", incl->exec_file); 01813 else 01814 fprintf(f,"#include \"%s\"\n", incl->included_file); 01815 fclose(f); 01816 incl->output = 1; 01817 ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */ 01818 fi = 0; 01819 } 01820 } 01821 ao2_ref(fileset, -1); /* this should destroy the hash container */ 01822 01823 return 0; 01824 }
int read_config_maps | ( | void | ) |
Exposed re-initialization method for core process This method is intended for use only with the core re-initialization and is not designed to be called from any user applications.
Definition at line 1874 of file config.c.
References append_mapping(), ast_config_destroy(), ast_config_internal_load(), ast_config_new(), ast_copy_string(), ast_log(), ast_variable_browse(), buf, clear_config_maps(), config, ast_flags::flags, LOG_WARNING, ast_config::max_include_level, ast_variable::name, ast_variable::next, strsep(), table, and ast_variable::value.
Referenced by main().
01875 { 01876 struct ast_config *config, *configtmp; 01877 struct ast_variable *v; 01878 char *driver, *table, *database, *stringp, *tmp; 01879 struct ast_flags flags = { 0 }; 01880 01881 clear_config_maps(); 01882 01883 configtmp = ast_config_new(); 01884 configtmp->max_include_level = 1; 01885 config = ast_config_internal_load(extconfig_conf, configtmp, flags, "", "extconfig"); 01886 if (!config) { 01887 ast_config_destroy(configtmp); 01888 return 0; 01889 } 01890 01891 for (v = ast_variable_browse(config, "settings"); v; v = v->next) { 01892 char buf[512]; 01893 ast_copy_string(buf, v->value, sizeof(buf)); 01894 stringp = buf; 01895 driver = strsep(&stringp, ","); 01896 01897 if ((tmp = strchr(stringp, '\"'))) 01898 stringp = tmp; 01899 01900 /* check if the database text starts with a double quote */ 01901 if (*stringp == '"') { 01902 stringp++; 01903 database = strsep(&stringp, "\""); 01904 strsep(&stringp, ","); 01905 } else { 01906 /* apparently this text has no quotes */ 01907 database = strsep(&stringp, ","); 01908 } 01909 01910 table = strsep(&stringp, ","); 01911 01912 if (!strcmp(v->name, extconfig_conf)) { 01913 ast_log(LOG_WARNING, "Cannot bind '%s'!\n", extconfig_conf); 01914 continue; 01915 } 01916 01917 if (!strcmp(v->name, "asterisk.conf")) { 01918 ast_log(LOG_WARNING, "Cannot bind 'asterisk.conf'!\n"); 01919 continue; 01920 } 01921 01922 if (!strcmp(v->name, "logger.conf")) { 01923 ast_log(LOG_WARNING, "Cannot bind 'logger.conf'!\n"); 01924 continue; 01925 } 01926 01927 if (!driver || !database) 01928 continue; 01929 if (!strcasecmp(v->name, "sipfriends")) { 01930 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"); 01931 append_mapping("sipusers", driver, database, table ? table : "sipfriends"); 01932 append_mapping("sippeers", driver, database, table ? table : "sipfriends"); 01933 } else if (!strcasecmp(v->name, "iaxfriends")) { 01934 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"); 01935 append_mapping("iaxusers", driver, database, table ? table : "iaxfriends"); 01936 append_mapping("iaxpeers", driver, database, table ? table : "iaxfriends"); 01937 } else 01938 append_mapping(v->name, driver, database, table); 01939 } 01940 01941 ast_config_destroy(config); 01942 return 0; 01943 }
int register_config_cli | ( | void | ) |
Exposed initialization method for core process This method is intended for use only with the core initialization and is not designed to be called from any user applications.
Definition at line 2533 of file config.c.
References ast_cli_register_multiple(), and cli_config.
Referenced by main().
02534 { 02535 ast_cli_register_multiple(cli_config, sizeof(cli_config) / sizeof(struct ast_cli_entry)); 02536 return 0; 02537 }