Configuration File Parser. More...
#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) |
Load a config file. | |
#define | CONFIG_STATUS_FILEINVALID (void *)-2 |
#define | CONFIG_STATUS_FILEMISSING (void *)0 |
#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, 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 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) |
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 int | realtime_update2 (const char *database, const char *table, va_list ap) |
typedef struct 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), CONFIG_FLAG_NOREALTIME = (1 << 3) } |
enum | ast_parse_flags { PARSE_TYPE = 0x000f, PARSE_INT32 = 0x0001, PARSE_UINT32 = 0x0002, PARSE_DOUBLE = 0x0003, PARSE_ADDR = 0x000e, 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) |
struct 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. | |
struct ast_variable * | ast_category_first (struct ast_category *cat) |
given a pointer to a category, return the root variable. | |
struct 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. | |
struct 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) |
struct ast_variable * | ast_category_root (struct ast_config *config, char *cat) |
returns the root ast_variable of a config | |
int | ast_check_realtime (const char *family) |
Check if realtime engine is configured for family. | |
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. | |
struct ast_category * | ast_config_get_current_category (const struct ast_config *cfg) |
Retrieve the current category name being built. | |
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) |
struct ast_config * | ast_config_load2 (const char *filename, const char *who_asked, struct ast_flags flags) |
Load a config file. | |
struct 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. | |
void | ast_config_set_current_category (struct ast_config *cfg, const struct ast_category *cat) |
Set the category within the configuration as being current. | |
int | ast_config_text_file_save (const char *filename, const struct ast_config *cfg, const char *generator) |
int | ast_destroy_realtime (const char *family, const char *keyfield, const char *lookup,...) attribute_sentinel |
Destroy realtime configuration. | |
struct ast_config_include * | ast_include_find (struct ast_config *conf, const char *included_file) |
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) |
void | ast_include_rename (struct ast_config *conf, const char *from_file, const char *to_file) |
AST_INLINE_API (int ast_rq_is_int(require_type type),{switch(type){case RQ_INTEGER1:case RQ_UINTEGER1:case RQ_INTEGER2:case RQ_UINTEGER2:case RQ_INTEGER3:case RQ_UINTEGER3:case RQ_INTEGER4:case RQ_UINTEGER4:case RQ_INTEGER8:case RQ_UINTEGER8:return 1;default:return 0;}}) char *ast_realtime_decode_chunk(char *chunk) | |
Check if require type is an integer type. | |
struct ast_variable * | ast_load_realtime (const char *family,...) attribute_sentinel |
Retrieve realtime configuration. | |
struct ast_variable * | ast_load_realtime_all (const char *family,...) attribute_sentinel |
struct 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. | |
char * | ast_realtime_encode_chunk (struct ast_str **dest, ssize_t maxlen, const char *chunk) |
Encodes a chunk of data for realtime. | |
int | ast_realtime_require_field (const char *family,...) attribute_sentinel |
Inform realtime what fields that may be stored. | |
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_update2_realtime (const char *family,...) attribute_sentinel |
Update realtime configuration. | |
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) |
struct ast_variable * | ast_variable_browse (const struct ast_config *config, const char *category) |
Goes through variables. | |
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) |
struct 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. | |
struct ast_variable * | ast_variables_dup (struct ast_variable *var) |
Duplicate 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. | |
int | register_config_cli (void) |
Exposed initialization method for core process. |
Configuration File Parser.
Definition in file config.h.
#define ast_config_load | ( | filename, | |||
flags | ) | ast_config_load2(filename, AST_MODULE, flags) |
Load a config file.
filename | path of file to open. If no preceding '/' character, path is considered relative to AST_CONFIG_DIR | |
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). |
Create a config structure from a given configuration file.
NULL | on error |
Definition at line 170 of file config.h.
Referenced by adsi_load(), advanced_options(), aji_load_config(), ast_plc_reload(), conf_exec(), config_function_read(), config_load(), config_module(), directory_exec(), festival_exec(), find_conf(), gtalk_load_config(), handle_cli_dialplan_save(), jingle_load_config(), load_config(), load_config_meetme(), load_module(), load_moh_classes(), load_odbc_config(), load_pktccops_config(), make_email_file(), odbc_load_module(), osp_load(), parse_config(), pbx_load_config(), pbx_load_users(), play_message(), prep_email_sub_vars(), read_agent_config(), read_password_from_file(), realtime_directory(), reload(), reload_config(), reload_followme(), reload_module(), reload_queue_rules(), reload_queues(), set_config(), setup_dahdi_int(), sla_load_config(), smdi_load(), tds_load_module(), vm_change_password(), and vm_forwardoptions().
#define CONFIG_STATUS_FILEINVALID (void *)-2 |
Definition at line 52 of file config.h.
Referenced by __ast_http_load(), __ast_http_post_load(), __ast_udptl_reload(), __init_manager(), _dsp_init(), action_getconfig(), action_getconfigjson(), action_listcategories(), action_updateconfig(), adsi_load(), advanced_options(), aji_load_config(), ast_config_internal_load(), ast_config_load2(), ast_plc_reload(), ast_readconfig(), conf_exec(), config_function_read(), config_load(), config_module(), config_text_file_load(), directory_exec(), do_reload(), festival_exec(), find_conf(), gtalk_load_config(), iax_provision_reload(), init_logger_chain(), initialize_cc_max_requests(), jingle_load_config(), load_config(), load_config_meetme(), load_indications(), load_module(), load_modules(), load_moh_classes(), load_odbc_config(), misdn_cfg_init(), odbc_load_module(), osp_load(), parse_config(), pbx_load_config(), play_message(), private_enum_init(), read_agent_config(), read_config_maps(), realtime_directory(), reload(), reload_config(), reload_followme(), reload_module(), reload_queue_rules(), reload_queues(), rtp_reload(), run_startup_commands(), set_config(), setup_dahdi_int(), sla_load_config(), smdi_load(), tds_load_module(), vm_change_password(), and vm_forwardoptions().
#define CONFIG_STATUS_FILEMISSING (void *)0 |
Definition at line 50 of file config.h.
Referenced by __ast_http_load(), __ast_http_post_load(), __ast_udptl_reload(), _dsp_init(), action_getconfig(), adsi_load(), aji_load_config(), ast_plc_reload(), ast_readconfig(), do_reload(), load_config(), load_indications(), load_modules(), load_moh_classes(), load_odbc_config(), parse_config(), private_enum_init(), rtp_reload(), and run_startup_commands().
#define CONFIG_STATUS_FILEUNCHANGED (void *)-1 |
Definition at line 51 of file config.h.
Referenced by __ast_http_load(), __ast_http_post_load(), __ast_udptl_reload(), __init_manager(), _dsp_init(), adsi_load(), aji_load_config(), ast_cli_perms_init(), ast_config_internal_load(), ast_config_load2(), ast_plc_reload(), ast_readconfig(), config_function_read(), config_module(), config_text_file_load(), do_reload(), iax_provision_reload(), load_config(), load_indications(), 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(), rtp_reload(), run_startup_commands(), set_config(), setup_dahdi_int(), 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 729 of file config.h.
Referenced by store_config_core().
#define CV_DSTR | ( | __x, | |||
__dst | ) | CV_F(__x, ast_free(__dst); __dst = ast_strdup(__val)) |
#define CV_END } while (0) |
close a variable parsing block
Definition at line 720 of file config.h.
Referenced by store_config_core(), and store_config_tone_zone().
#define CV_F | ( | __pattern, | |||
__body | ) | if (!strcasecmp((__var), __pattern)) { __body; break; } |
call a generic function if the name matches.
Definition at line 723 of file config.h.
Referenced by store_config_core(), and store_config_tone_zone().
#define CV_START | ( | __in_var, | |||
__in_val | ) |
do { \ const char *__var = __in_var; \ const char *__val = __in_val;
the macro to open a block for variable parsing
Definition at line 714 of file config.h.
Referenced by store_config_core(), and store_config_tone_zone().
#define CV_STR | ( | __x, | |||
__dst | ) | CV_F(__x, ast_copy_string(__dst, __val, sizeof(__dst))) |
Definition at line 731 of file config.h.
Referenced by store_config_core(), and store_config_tone_zone().
#define CV_STRFIELD | ( | __x, | |||
__obj, | |||||
__field | ) | CV_F(__x, ast_string_field_set(__obj, __field, __val)) |
Definition at line 733 of file config.h.
Referenced by store_config_core().
#define CV_UINT | ( | __x, | |||
__dst | ) | CV_F(__x, (__dst) = strtoul(__val, NULL, 0) ) |
Definition at line 730 of file config.h.
Referenced by store_config_core().
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 int realtime_update2(const char *database, const char *table, 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 /*! Don't attempt to load from realtime (typically called from a realtime driver dependency) */ 00047 CONFIG_FLAG_NOREALTIME = (1 << 3), 00048 };
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.
PARSE_TYPE | |
PARSE_INT32 | |
PARSE_UINT32 | |
PARSE_DOUBLE | |
PARSE_ADDR | |
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 607 of file config.h.
00607 { 00608 /* low 4 bits of flags are used for the operand type */ 00609 PARSE_TYPE = 0x000f, 00610 /* numeric types, with optional default value and bound checks. 00611 * Additional arguments are passed by value. 00612 */ 00613 PARSE_INT32 = 0x0001, 00614 PARSE_UINT32 = 0x0002, 00615 PARSE_DOUBLE = 0x0003, 00616 #if 0 /* not supported yet */ 00617 PARSE_INT16 = 0x0004, 00618 PARSE_UINT16 = 0x0005, 00619 #endif 00620 00621 /* Returns a struct ast_sockaddr, with optional default value 00622 * (passed by reference) and port handling (accept, ignore, 00623 * require, forbid). The format is 'ipaddress[:port]'. IPv6 address 00624 * literals need square brackets around them if a port is specified. 00625 */ 00626 PARSE_ADDR = 0x000e, 00627 00628 /* Returns a struct sockaddr_in, with optional default value 00629 * (passed by reference) and port handling (accept, ignore, 00630 * require, forbid). The format is 'host.name[:port]' 00631 */ 00632 PARSE_INADDR = 0x000f, 00633 00634 /* Other data types can be added as needed */ 00635 00636 /* If PARSE_DEFAULT is set, next argument is a default value 00637 * which is returned in case of error. The argument is passed 00638 * by value in case of numeric types, by reference in other cases. 00639 */ 00640 PARSE_DEFAULT = 0x0010, /* assign default on error */ 00641 00642 /* Request a range check, applicable to numbers. Two additional 00643 * arguments are passed by value, specifying the low-high end of 00644 * the range (inclusive). An error is returned if the value 00645 * is outside or inside the range, respectively. 00646 */ 00647 PARSE_IN_RANGE = 0x0020, /* accept values inside a range */ 00648 PARSE_OUT_RANGE = 0x0040, /* accept values outside a range */ 00649 00650 /* Port handling, for ast_sockaddr. accept/ignore/require/forbid 00651 * port number after the hostname or address. 00652 */ 00653 PARSE_PORT_MASK = 0x0300, /* 0x000: accept port if present */ 00654 PARSE_PORT_IGNORE = 0x0100, /* 0x100: ignore port if present */ 00655 PARSE_PORT_REQUIRE = 0x0200, /* 0x200: require port number */ 00656 PARSE_PORT_FORBID = 0x0300, /* 0x100: forbid port number */ 00657 };
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 57 of file config.h.
00057 { 00058 RQ_INTEGER1, 00059 RQ_UINTEGER1, 00060 RQ_INTEGER2, 00061 RQ_UINTEGER2, 00062 RQ_INTEGER3, 00063 RQ_UINTEGER3, 00064 RQ_INTEGER4, 00065 RQ_UINTEGER4, 00066 RQ_INTEGER8, 00067 RQ_UINTEGER8, 00068 RQ_CHAR, 00069 RQ_FLOAT, 00070 RQ_DATE, 00071 RQ_DATETIME, 00072 } require_type;
void ast_category_append | ( | struct ast_config * | config, | |
struct ast_category * | cat | |||
) |
Definition at line 687 of file config.c.
References ast_config::current, ast_config::include_level, ast_category::include_level, ast_config::last, ast_category::next, and ast_config::root.
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(), realtime_multi_pgsql(), and write_password_to_file().
00688 { 00689 if (config->last) 00690 config->last->next = category; 00691 else 00692 config->root = category; 00693 category->include_level = config->include_level; 00694 config->last = category; 00695 config->current = category; 00696 }
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 774 of file config.c.
References ast_config::last_browse, ast_category::name, ast_category::next, next_available_category(), and ast_config::root.
Referenced by __init_manager(), __queues_show(), action_getconfig(), action_getconfigjson(), action_listcategories(), actual_load_config(), aji_load_config(), ast_cli_perms_init(), AST_LIST_HEAD_NOLOCK(), complete_sipnotify(), conf_exec(), config_load(), find_queue_by_name_rt(), find_realtime(), get_insecure_variable_from_config(), get_insecure_variable_from_sipregs(), gtalk_load_config(), iax_provision_reload(), jingle_load_config(), load_config(), load_indications(), load_module(), load_moh_classes(), load_odbc_config(), load_pktccops_config(), load_tech_calendars(), misdn_cfg_init(), osp_load(), parse_config(), pbx_load_config(), pbx_load_users(), process_config(), queues_data_provider_get(), read_agent_config(), realtime_directory(), realtime_switch_common(), reload(), reload_config(), reload_followme(), reload_queue_rules(), reload_queues(), search_directory(), set_config(), setup_dahdi_int(), show_users_realtime(), sla_load_config(), update_realtime_members(), and vm_change_password().
00775 { 00776 struct ast_category *cat; 00777 00778 if (!prev) { 00779 /* First time browse. */ 00780 cat = config->root; 00781 } else if (config->last_browse && (config->last_browse->name == prev)) { 00782 /* Simple last browse found. */ 00783 cat = config->last_browse->next; 00784 } else { 00785 /* 00786 * Config changed since last browse. 00787 * 00788 * First try cheap last browse search. (Rebrowsing a different 00789 * previous category?) 00790 */ 00791 for (cat = config->root; cat; cat = cat->next) { 00792 if (cat->name == prev) { 00793 /* Found it. */ 00794 cat = cat->next; 00795 break; 00796 } 00797 } 00798 if (!cat) { 00799 /* 00800 * Have to do it the hard way. (Last category was deleted and 00801 * re-added?) 00802 */ 00803 for (cat = config->root; cat; cat = cat->next) { 00804 if (!strcasecmp(cat->name, prev)) { 00805 /* Found it. */ 00806 cat = cat->next; 00807 break; 00808 } 00809 } 00810 } 00811 } 00812 00813 if (cat) 00814 cat = next_available_category(cat); 00815 00816 config->last_browse = cat; 00817 return (cat) ? cat->name : NULL; 00818 }
int ast_category_delete | ( | struct ast_config * | cfg, | |
const char * | category | |||
) |
Definition at line 940 of file config.c.
References ast_category_destroy(), ast_config::last, ast_category::next, and ast_config::root.
Referenced by handle_updates().
00941 { 00942 struct ast_category *prev=NULL, *cat; 00943 00944 cat = cfg->root; 00945 while (cat) { 00946 if (cat->name == category) { 00947 if (prev) { 00948 prev->next = cat->next; 00949 if (cat == cfg->last) 00950 cfg->last = prev; 00951 } else { 00952 cfg->root = cat->next; 00953 if (cat == cfg->last) 00954 cfg->last = NULL; 00955 } 00956 ast_category_destroy(cat); 00957 return 0; 00958 } 00959 prev = cat; 00960 cat = cat->next; 00961 } 00962 00963 prev = NULL; 00964 cat = cfg->root; 00965 while (cat) { 00966 if (!strcasecmp(cat->name, category)) { 00967 if (prev) { 00968 prev->next = cat->next; 00969 if (cat == cfg->last) 00970 cfg->last = prev; 00971 } else { 00972 cfg->root = cat->next; 00973 if (cat == cfg->last) 00974 cfg->last = NULL; 00975 } 00976 ast_category_destroy(cat); 00977 return 0; 00978 } 00979 prev = cat; 00980 cat = cat->next; 00981 } 00982 return -1; 00983 }
void ast_category_destroy | ( | struct ast_category * | cat | ) |
Definition at line 726 of file config.c.
References ast_comment_destroy(), ast_destroy_template_list(), ast_free, ast_variables_destroy(), ast_category::file, ast_category::last, ast_category::precomments, ast_category::root, ast_category::sameline, and ast_category::trailing.
Referenced by add_cfg_entry(), ast_category_delete(), ast_category_new(), ast_config_destroy(), process_text_line(), realtime_multi_odbc(), and write_password_to_file().
00727 { 00728 ast_variables_destroy(cat->root); 00729 cat->root = NULL; 00730 cat->last = NULL; 00731 ast_comment_destroy(&cat->precomments); 00732 ast_comment_destroy(&cat->sameline); 00733 ast_comment_destroy(&cat->trailing); 00734 ast_destroy_template_list(cat); 00735 ast_free(cat->file); 00736 ast_free(cat); 00737 }
struct ast_variable* ast_category_detach_variables | ( | struct ast_category * | cat | ) | [read] |
Definition at line 820 of file config.c.
References ast_category::last, and ast_category::root.
Referenced by realtime_switch_common().
00821 { 00822 struct ast_variable *v; 00823 00824 v = cat->root; 00825 cat->root = NULL; 00826 cat->last = NULL; 00827 00828 return v; 00829 }
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 985 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().
00986 { 00987 struct ast_category *cat; 00988 00989 for (cat = cfg->root; cat; cat = cat->next) { 00990 if (!strcasecmp(cat->name, category)) 00991 continue; 00992 ast_variables_destroy(cat->root); 00993 cat->root = NULL; 00994 cat->last = NULL; 00995 return 0; 00996 } 00997 00998 return -1; 00999 }
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 682 of file config.c.
References ast_category_get().
00683 { 00684 return !!ast_category_get(config, category_name); 00685 }
struct ast_variable* ast_category_first | ( | struct ast_category * | cat | ) | [read] |
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 760 of file config.c.
References ast_category::root.
Referenced by process_text_line().
00761 { 00762 return (cat) ? cat->root : NULL; 00763 }
struct ast_category* ast_category_get | ( | const struct ast_config * | config, | |
const char * | category_name | |||
) | [read] |
Retrieve a category if it exists.
config | which config to use | |
category_name | name of the category you're looking for |
This will search through the categories within a given config file for a match.
pointer | to category if found | |
NULL | if not. |
Definition at line 677 of file config.c.
References category_get().
Referenced by ast_category_exist(), ast_category_root(), ast_variable_browse(), handle_updates(), realtime_directory(), realtime_switch_common(), vm_change_password(), and vm_forwardoptions().
00678 { 00679 return category_get(config, category_name, 0); 00680 }
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 698 of file config.c.
References ast_category::name, ast_category::next, and ast_config::root.
Referenced by handle_updates().
00699 { 00700 struct ast_category *cur_category; 00701 00702 if (!cat || !match) 00703 return; 00704 if (!strcasecmp(config->root->name, match)) { 00705 cat->next = config->root; 00706 config->root = cat; 00707 return; 00708 } 00709 for (cur_category = config->root; cur_category; cur_category = cur_category->next) { 00710 if (!strcasecmp(cur_category->next->name, match)) { 00711 cat->next = cur_category->next; 00712 cur_category->next = cat; 00713 break; 00714 } 00715 } 00716 }
struct ast_category* ast_category_new | ( | const char * | name, | |
const char * | in_file, | |||
int | lineno | |||
) | [read] |
Create a category structure.
Definition at line 641 of file config.c.
References ast_calloc, ast_category_destroy(), ast_copy_string(), ast_strdup, ast_category::file, ast_category::lineno, and ast_category::name.
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(), realtime_multi_pgsql(), and write_password_to_file().
00642 { 00643 struct ast_category *category; 00644 00645 category = ast_calloc(1, sizeof(*category)); 00646 if (!category) { 00647 return NULL; 00648 } 00649 category->file = ast_strdup(in_file); 00650 if (!category->file) { 00651 ast_category_destroy(category); 00652 return NULL; 00653 } 00654 ast_copy_string(category->name, name, sizeof(category->name)); 00655 category->lineno = lineno; /* if you don't know the lineno, set it to 999999 or something real big */ 00656 return category; 00657 }
void ast_category_rename | ( | struct ast_category * | cat, | |
const char * | name | |||
) |
Definition at line 831 of file config.c.
References ast_copy_string(), and ast_category::name.
Referenced by handle_updates(), realtime_multi_curl(), realtime_multi_ldap(), realtime_multi_odbc(), and realtime_multi_pgsql().
00832 { 00833 ast_copy_string(cat->name, name, sizeof(cat->name)); 00834 }
struct ast_variable* ast_category_root | ( | struct ast_config * | config, | |
char * | cat | |||
) | [read] |
returns the root ast_variable of a config
config | pointer to an ast_config data structure | |
cat | name of the category for which you want the root |
Definition at line 765 of file config.c.
References ast_category_get(), and ast_category::root.
Referenced by get_insecure_variable_from_config(), and get_insecure_variable_from_sipregs().
00766 { 00767 struct ast_category *category = ast_category_get(config, cat); 00768 00769 if (category) 00770 return category->root; 00771 return NULL; 00772 }
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 2421 of file config.c.
References ast_realtime_enabled(), and find_engine().
Referenced by __queues_show(), _sip_show_peer(), _sip_show_peers(), ast_queue_log(), close_mailbox(), copy_plain_file(), destroy_association(), find_realtime_gw(), handle_response_peerpoke(), handle_voicemail_show_users(), leave_voicemail(), load_module(), load_moh_classes(), local_ast_moh_start(), logger_queue_rt_start(), realtime_peer(), realtime_update_peer(), rename_file(), sip_poke_noanswer(), sip_show_settings(), and vm_delete().
02422 { 02423 struct ast_config_engine *eng; 02424 if (!ast_realtime_enabled()) { 02425 return 0; /* There are no engines at all so fail early */ 02426 } 02427 02428 eng = find_engine(family, 1, NULL, 0, NULL, 0); 02429 if (eng) 02430 return 1; 02431 return 0; 02432 }
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 1001 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_load(), __ast_http_post_load(), __ast_udptl_reload(), __init_manager(), __queues_show(), _dsp_init(), action_getconfig(), action_getconfigjson(), action_listcategories(), action_updateconfig(), adsi_load(), advanced_options(), aji_load_config(), ast_cli_perms_init(), ast_config_load2(), ast_load_realtime_multientry(), ast_plc_reload(), ast_readconfig(), conf_exec(), config_function_read(), config_load(), config_module(), directory_exec(), do_reload(), festival_exec(), find_conf(), find_realtime(), get_insecure_variable_from_sippeers(), get_insecure_variable_from_sipregs(), gtalk_load_config(), handle_cli_dialplan_save(), iax_provision_reload(), init_logger_chain(), initialize_cc_max_requests(), jingle_load_config(), load_config(), load_config_meetme(), load_indications(), load_module(), load_modules(), load_moh_classes(), load_odbc_config(), load_pktccops_config(), load_realtime_queue(), make_email_file(), misdn_cfg_init(), odbc_load_module(), osp_load(), parse_config(), pbx_load_config(), pbx_load_users(), play_message(), prep_email_sub_vars(), private_enum_init(), queues_data_provider_get(), read_agent_config(), read_config_maps(), read_password_from_file(), realtime_directory(), realtime_multi_handler(), realtime_multi_pgsql(), realtime_switch_common(), reload(), reload_config(), reload_followme(), reload_module(), reload_queue_rules(), reload_queues(), rtp_reload(), run_startup_commands(), set_config(), setup_dahdi_int(), show_users_realtime(), sla_load_config(), smdi_load(), tds_load_module(), unload_module(), update_realtime_members(), vm_forwardoptions(), and write_password_to_file().
01002 { 01003 struct ast_category *cat, *catn; 01004 01005 if (!cfg) 01006 return; 01007 01008 ast_includes_destroy(cfg->includes); 01009 01010 cat = cfg->root; 01011 while (cat) { 01012 catn = cat; 01013 cat = cat->next; 01014 ast_category_destroy(catn); 01015 } 01016 ast_free(cfg); 01017 }
int ast_config_engine_deregister | ( | struct ast_config_engine * | del | ) |
Deregister config engine.
0 | Always |
Definition at line 2231 of file config.c.
References ast_mutex_lock, ast_mutex_unlock, config_lock, last, and ast_config_engine::next.
Referenced by unload_module().
02232 { 02233 struct ast_config_engine *ptr, *last=NULL; 02234 02235 ast_mutex_lock(&config_lock); 02236 02237 for (ptr = config_engine_list; ptr; ptr=ptr->next) { 02238 if (ptr == del) { 02239 if (last) 02240 last->next = ptr->next; 02241 else 02242 config_engine_list = ptr->next; 02243 break; 02244 } 02245 last = ptr; 02246 } 02247 02248 ast_mutex_unlock(&config_lock); 02249 02250 return 0; 02251 }
int ast_config_engine_register | ( | struct ast_config_engine * | newconfig | ) |
Register config engine.
1 | Always |
Definition at line 2212 of file config.c.
References ast_log(), ast_mutex_lock, ast_mutex_unlock, config_lock, LOG_NOTICE, and ast_config_engine::next.
Referenced by load_module().
02213 { 02214 struct ast_config_engine *ptr; 02215 02216 ast_mutex_lock(&config_lock); 02217 02218 if (!config_engine_list) { 02219 config_engine_list = new; 02220 } else { 02221 for (ptr = config_engine_list; ptr->next; ptr=ptr->next); 02222 ptr->next = new; 02223 } 02224 02225 ast_mutex_unlock(&config_lock); 02226 ast_log(LOG_NOTICE,"Registered Config Engine %s\n", new->name); 02227 02228 return 1; 02229 }
struct ast_category* ast_config_get_current_category | ( | const struct ast_config * | cfg | ) | [read] |
Retrieve the current category name being built.
API for backend configuration engines while building a configuration set.
Definition at line 1019 of file config.c.
References ast_config::current.
Referenced by config_curl(), config_odbc(), and config_text_file_load().
01020 { 01021 return cfg->current; 01022 }
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 | |||
) | [read] |
Definition at line 2293 of file config.c.
References ast_log(), ast_test_flag, CONFIG_FLAG_NOREALTIME, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, db, find_engine(), ast_config::include_level, ast_config_engine::load_func, LOG_WARNING, ast_config::max_include_level, and table.
Referenced by add_cfg_entry(), ast_config_load2(), config_curl(), config_ldap(), config_odbc(), config_pgsql(), process_text_line(), and read_config_maps().
02294 { 02295 char db[256]; 02296 char table[256]; 02297 struct ast_config_engine *loader = &text_file_engine; 02298 struct ast_config *result; 02299 02300 /* The config file itself bumps include_level by 1 */ 02301 if (cfg->max_include_level > 0 && cfg->include_level == cfg->max_include_level + 1) { 02302 ast_log(LOG_WARNING, "Maximum Include level (%d) exceeded\n", cfg->max_include_level); 02303 return NULL; 02304 } 02305 02306 cfg->include_level++; 02307 02308 if (!ast_test_flag(&flags, CONFIG_FLAG_NOREALTIME) && config_engine_list) { 02309 struct ast_config_engine *eng; 02310 02311 eng = find_engine(filename, 1, db, sizeof(db), table, sizeof(table)); 02312 02313 02314 if (eng && eng->load_func) { 02315 loader = eng; 02316 } else { 02317 eng = find_engine("global", 1, db, sizeof(db), table, sizeof(table)); 02318 if (eng && eng->load_func) 02319 loader = eng; 02320 } 02321 } 02322 02323 result = loader->load_func(db, table, filename, cfg, flags, suggested_include_file, who_asked); 02324 02325 if (result && result != CONFIG_STATUS_FILEINVALID && result != CONFIG_STATUS_FILEUNCHANGED) 02326 result->include_level--; 02327 else if (result != CONFIG_STATUS_FILEINVALID) 02328 cfg->include_level--; 02329 02330 return result; 02331 }
struct ast_config* ast_config_load2 | ( | const char * | filename, | |
const char * | who_asked, | |||
struct ast_flags | flags | |||
) | [read] |
Load a config file.
filename | path of file to open. If no preceding '/' character, path is considered relative to AST_CONFIG_DIR | |
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). |
Create a config structure from a given configuration file.
NULL | on error |
Definition at line 2333 of file config.c.
References ast_config_destroy(), ast_config_internal_load(), ast_config_new(), CONFIG_STATUS_FILEINVALID, and CONFIG_STATUS_FILEUNCHANGED.
Referenced by __ast_http_load(), __ast_http_post_load(), __ast_udptl_reload(), __init_manager(), _dsp_init(), action_getconfig(), action_getconfigjson(), action_listcategories(), action_updateconfig(), ast_cli_perms_init(), ast_readconfig(), do_reload(), iax_provision_reload(), init_logger_chain(), initialize_cc_max_requests(), load_config(), load_indications(), load_modules(), misdn_cfg_init(), private_enum_init(), rtp_reload(), run_startup_commands(), and set_config().
02334 { 02335 struct ast_config *cfg; 02336 struct ast_config *result; 02337 02338 cfg = ast_config_new(); 02339 if (!cfg) 02340 return NULL; 02341 02342 result = ast_config_internal_load(filename, cfg, flags, "", who_asked); 02343 if (!result || result == CONFIG_STATUS_FILEUNCHANGED || result == CONFIG_STATUS_FILEINVALID) 02344 ast_config_destroy(cfg); 02345 02346 return result; 02347 }
struct ast_config* ast_config_new | ( | void | ) | [read] |
Create a new base configuration structure.
Definition at line 852 of file config.c.
References ast_calloc, config, MAX_INCLUDE_LEVEL, and ast_config::max_include_level.
Referenced by ast_config_load2(), load_realtime_queue(), read_config_maps(), realtime_multi_curl(), realtime_multi_handler(), realtime_multi_ldap(), realtime_multi_odbc(), realtime_multi_pgsql(), setup_dahdi_int(), and write_password_to_file().
00853 { 00854 struct ast_config *config; 00855 00856 if ((config = ast_calloc(1, sizeof(*config)))) 00857 config->max_include_level = MAX_INCLUDE_LEVEL; 00858 return config; 00859 }
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 582 of file config.c.
References ast_variable_retrieve().
Referenced by actual_load_config(), AST_LIST_HEAD_NOLOCK(), and pbx_load_users().
00583 { 00584 const char *tmp; 00585 tmp = ast_variable_retrieve(cfg, cat, var); 00586 if (!tmp) { 00587 tmp = ast_variable_retrieve(cfg, "general", var); 00588 } 00589 return tmp; 00590 }
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 1024 of file config.c.
References ast_config::current.
01025 { 01026 /* cast below is just to silence compiler warning about dropping "const" */ 01027 cfg->current = (struct ast_category *) cat; 01028 }
int ast_config_text_file_save | ( | const char * | filename, | |
const struct ast_config * | cfg, | |||
const char * | generator | |||
) |
Definition at line 1826 of file config.c.
References ao2_container_alloc, ao2_ref, ast_debug, AST_LIST_EMPTY, AST_LIST_LAST, AST_LIST_TRAVERSE, ast_verb, ast_variable::blanklines, ast_comment::cmt, errno, ast_config_include::exec, ast_config_include::exec_file, f, ast_variable::file, 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_variable::lineno, ast_category::lineno, ast_variable::name, ast_category_template_instance::name, ast_category::name, ast_category::next, ast_variable::next, ast_comment::next, ast_config_include::next, ast_variable::object, option_debug, ast_config_include::output, ast_variable::precomments, ast_category::precomments, ast_category::root, ast_config::root, ast_variable::sameline, ast_category::sameline, set_fn(), ast_category::template_instances, ast_variable::trailing, ast_category::trailing, ast_variable::value, and var.
Referenced by action_updateconfig(), config_text_file_save(), vm_change_password(), vm_forwardoptions(), and write_password_to_file().
01827 { 01828 FILE *f; 01829 char fn[PATH_MAX]; 01830 struct ast_variable *var; 01831 struct ast_category *cat; 01832 struct ast_comment *cmt; 01833 struct ast_config_include *incl; 01834 int blanklines = 0; 01835 struct ao2_container *fileset; 01836 struct inclfile *fi; 01837 01838 fileset = ao2_container_alloc(1023, hash_string, hashtab_compare_strings); 01839 if (!fileset) { 01840 /* Container creation failed. */ 01841 return -1; 01842 } 01843 01844 /* reset all the output flags, in case this isn't our first time saving this data */ 01845 for (incl = cfg->includes; incl; incl = incl->next) { 01846 incl->output = 0; 01847 } 01848 01849 /* go thru all the inclusions and make sure all the files involved (configfile plus all its inclusions) 01850 are all truncated to zero bytes and have that nice header*/ 01851 for (incl = cfg->includes; incl; incl = incl->next) { 01852 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*/ 01853 /* normally, fn is just set to incl->included_file, prepended with config dir if relative */ 01854 fi = set_fn(fn, sizeof(fn), incl->included_file, configfile, fileset); 01855 f = fopen(fn, "w"); 01856 if (f) { 01857 gen_header(f, configfile, fn, generator); 01858 fclose(f); /* this should zero out the file */ 01859 } else { 01860 ast_debug(1, "Unable to open for writing: %s\n", fn); 01861 ast_verb(2, "Unable to write %s (%s)", fn, strerror(errno)); 01862 } 01863 if (fi) { 01864 ao2_ref(fi, -1); 01865 } 01866 } 01867 } 01868 01869 /* just set fn to absolute ver of configfile */ 01870 fi = set_fn(fn, sizeof(fn), 0, configfile, fileset); 01871 if ( 01872 #ifdef __CYGWIN__ 01873 (f = fopen(fn, "w+")) 01874 #else 01875 (f = fopen(fn, "w")) 01876 #endif 01877 ) { 01878 ast_verb(2, "Saving '%s': ", fn); 01879 gen_header(f, configfile, fn, generator); 01880 cat = cfg->root; 01881 fclose(f); 01882 if (fi) { 01883 ao2_ref(fi, -1); 01884 } 01885 01886 /* from here out, we open each involved file and concat the stuff we need to add to the end and immediately close... */ 01887 /* since each var, cat, and associated comments can come from any file, we have to be 01888 mobile, and open each file, print, and close it on an entry-by-entry basis */ 01889 01890 while (cat) { 01891 fi = set_fn(fn, sizeof(fn), cat->file, configfile, fileset); 01892 f = fopen(fn, "a"); 01893 if (!f) { 01894 ast_debug(1, "Unable to open for writing: %s\n", fn); 01895 ast_verb(2, "Unable to write %s (%s)", fn, strerror(errno)); 01896 if (fi) { 01897 ao2_ref(fi, -1); 01898 } 01899 ao2_ref(fileset, -1); 01900 return -1; 01901 } 01902 01903 /* dump any includes that happen before this category header */ 01904 for (incl=cfg->includes; incl; incl = incl->next) { 01905 if (strcmp(incl->include_location_file, cat->file) == 0){ 01906 if (cat->lineno > incl->include_location_lineno && !incl->output) { 01907 if (incl->exec) 01908 fprintf(f,"#exec \"%s\"\n", incl->exec_file); 01909 else 01910 fprintf(f,"#include \"%s\"\n", incl->included_file); 01911 incl->output = 1; 01912 } 01913 } 01914 } 01915 01916 insert_leading_blank_lines(f, fi, cat->precomments, cat->lineno); 01917 /* Dump section with any appropriate comment */ 01918 for (cmt = cat->precomments; cmt; cmt=cmt->next) { 01919 char *cmtp = cmt->cmt; 01920 while (cmtp && *cmtp == ';' && *(cmtp+1) == '!') { 01921 char *cmtp2 = strchr(cmtp+1, '\n'); 01922 if (cmtp2) 01923 cmtp = cmtp2+1; 01924 else cmtp = 0; 01925 } 01926 if (cmtp) 01927 fprintf(f,"%s", cmtp); 01928 } 01929 fprintf(f, "[%s]", cat->name); 01930 if (cat->ignored || !AST_LIST_EMPTY(&cat->template_instances)) { 01931 fprintf(f, "("); 01932 if (cat->ignored) { 01933 fprintf(f, "!"); 01934 } 01935 if (cat->ignored && !AST_LIST_EMPTY(&cat->template_instances)) { 01936 fprintf(f, ","); 01937 } 01938 if (!AST_LIST_EMPTY(&cat->template_instances)) { 01939 struct ast_category_template_instance *x; 01940 AST_LIST_TRAVERSE(&cat->template_instances, x, next) { 01941 fprintf(f,"%s",x->name); 01942 if (x != AST_LIST_LAST(&cat->template_instances)) 01943 fprintf(f,","); 01944 } 01945 } 01946 fprintf(f, ")"); 01947 } 01948 for(cmt = cat->sameline; cmt; cmt=cmt->next) 01949 { 01950 fprintf(f,"%s", cmt->cmt); 01951 } 01952 if (!cat->sameline) 01953 fprintf(f,"\n"); 01954 for (cmt = cat->trailing; cmt; cmt=cmt->next) { 01955 if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!') 01956 fprintf(f,"%s", cmt->cmt); 01957 } 01958 fclose(f); 01959 if (fi) { 01960 ao2_ref(fi, -1); 01961 } 01962 01963 var = cat->root; 01964 while (var) { 01965 struct ast_category_template_instance *x; 01966 int found = 0; 01967 AST_LIST_TRAVERSE(&cat->template_instances, x, next) { 01968 struct ast_variable *v; 01969 for (v = x->inst->root; v; v = v->next) { 01970 if (!strcasecmp(var->name, v->name) && !strcmp(var->value, v->value)) { 01971 found = 1; 01972 break; 01973 } 01974 } 01975 if (found) 01976 break; 01977 } 01978 if (found) { 01979 var = var->next; 01980 continue; 01981 } 01982 fi = set_fn(fn, sizeof(fn), var->file, configfile, fileset); 01983 f = fopen(fn, "a"); 01984 if (!f) { 01985 ast_debug(1, "Unable to open for writing: %s\n", fn); 01986 ast_verb(2, "Unable to write %s (%s)", fn, strerror(errno)); 01987 if (fi) { 01988 ao2_ref(fi, -1); 01989 } 01990 ao2_ref(fileset, -1); 01991 return -1; 01992 } 01993 01994 /* dump any includes that happen before this category header */ 01995 for (incl=cfg->includes; incl; incl = incl->next) { 01996 if (strcmp(incl->include_location_file, var->file) == 0){ 01997 if (var->lineno > incl->include_location_lineno && !incl->output) { 01998 if (incl->exec) 01999 fprintf(f,"#exec \"%s\"\n", incl->exec_file); 02000 else 02001 fprintf(f,"#include \"%s\"\n", incl->included_file); 02002 incl->output = 1; 02003 } 02004 } 02005 } 02006 02007 insert_leading_blank_lines(f, fi, var->precomments, var->lineno); 02008 for (cmt = var->precomments; cmt; cmt=cmt->next) { 02009 if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!') 02010 fprintf(f,"%s", cmt->cmt); 02011 } 02012 if (var->sameline) 02013 fprintf(f, "%s %s %s %s", var->name, (var->object ? "=>" : "="), var->value, var->sameline->cmt); 02014 else 02015 fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="), var->value); 02016 for (cmt = var->trailing; cmt; cmt=cmt->next) { 02017 if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!') 02018 fprintf(f,"%s", cmt->cmt); 02019 } 02020 if (var->blanklines) { 02021 blanklines = var->blanklines; 02022 while (blanklines--) 02023 fprintf(f, "\n"); 02024 } 02025 02026 fclose(f); 02027 if (fi) { 02028 ao2_ref(fi, -1); 02029 } 02030 02031 var = var->next; 02032 } 02033 cat = cat->next; 02034 } 02035 if (!option_debug) 02036 ast_verb(2, "Saved\n"); 02037 } else { 02038 ast_debug(1, "Unable to open for writing: %s\n", fn); 02039 ast_verb(2, "Unable to write (%s)", strerror(errno)); 02040 if (fi) { 02041 ao2_ref(fi, -1); 02042 } 02043 ao2_ref(fileset, -1); 02044 return -1; 02045 } 02046 02047 /* Now, for files with trailing #include/#exec statements, 02048 we have to make sure every entry is output */ 02049 for (incl=cfg->includes; incl; incl = incl->next) { 02050 if (!incl->output) { 02051 /* open the respective file */ 02052 fi = set_fn(fn, sizeof(fn), incl->include_location_file, configfile, fileset); 02053 f = fopen(fn, "a"); 02054 if (!f) { 02055 ast_debug(1, "Unable to open for writing: %s\n", fn); 02056 ast_verb(2, "Unable to write %s (%s)", fn, strerror(errno)); 02057 if (fi) { 02058 ao2_ref(fi, -1); 02059 } 02060 ao2_ref(fileset, -1); 02061 return -1; 02062 } 02063 02064 /* output the respective include */ 02065 if (incl->exec) 02066 fprintf(f,"#exec \"%s\"\n", incl->exec_file); 02067 else 02068 fprintf(f,"#include \"%s\"\n", incl->included_file); 02069 fclose(f); 02070 incl->output = 1; 02071 if (fi) { 02072 ao2_ref(fi, -1); 02073 } 02074 } 02075 } 02076 ao2_ref(fileset, -1); /* this should destroy the hash container */ 02077 02078 return 0; 02079 }
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 2584 of file config.c.
References db, ast_config_engine::destroy_func, find_engine(), and table.
Referenced by cli_realtime_destroy(), function_realtime_readdestroy(), leave_voicemail(), and vm_delete().
02585 { 02586 struct ast_config_engine *eng; 02587 int res = -1, i; 02588 char db[256]; 02589 char table[256]; 02590 va_list ap; 02591 02592 va_start(ap, lookup); 02593 for (i = 1; ; i++) { 02594 if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) { 02595 if (eng->destroy_func && !(res = eng->destroy_func(db, table, keyfield, lookup, ap))) { 02596 break; 02597 } 02598 } else { 02599 break; 02600 } 02601 } 02602 va_end(ap); 02603 02604 return res; 02605 }
struct ast_config_include* ast_include_find | ( | struct ast_config * | conf, | |
const char * | included_file | |||
) | [read] |
Definition at line 464 of file config.c.
References ast_config_include::included_file, ast_config::includes, and ast_config_include::next.
Referenced by ast_include_new().
00465 { 00466 struct ast_config_include *x; 00467 for (x=conf->includes;x;x=x->next) { 00468 if (strcmp(x->included_file,included_file) == 0) 00469 return x; 00470 } 00471 return 0; 00472 }
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 | |||
) | [read] |
Definition at line 324 of file config.c.
References ast_calloc, ast_include_find(), ast_includes_destroy(), ast_log(), ast_strdup, ast_strlen_zero(), ast_config::includes, and LOG_WARNING.
Referenced by process_text_line().
00325 { 00326 /* a file should be included ONCE. Otherwise, if one of the instances is changed, 00327 * then all be changed. -- how do we know to include it? -- Handling modified 00328 * instances is possible, I'd have 00329 * to create a new master for each instance. */ 00330 struct ast_config_include *inc; 00331 struct stat statbuf; 00332 00333 inc = ast_include_find(conf, included_file); 00334 if (inc) { 00335 do { 00336 inc->inclusion_count++; 00337 snprintf(real_included_file_name, real_included_file_name_size, "%s~~%d", included_file, inc->inclusion_count); 00338 } while (stat(real_included_file_name, &statbuf) == 0); 00339 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); 00340 } else 00341 *real_included_file_name = 0; 00342 00343 inc = ast_calloc(1,sizeof(struct ast_config_include)); 00344 if (!inc) { 00345 return NULL; 00346 } 00347 inc->include_location_file = ast_strdup(from_file); 00348 inc->include_location_lineno = from_lineno; 00349 if (!ast_strlen_zero(real_included_file_name)) 00350 inc->included_file = ast_strdup(real_included_file_name); 00351 else 00352 inc->included_file = ast_strdup(included_file); 00353 00354 inc->exec = is_exec; 00355 if (is_exec) 00356 inc->exec_file = ast_strdup(exec_file); 00357 00358 if (!inc->include_location_file 00359 || !inc->included_file 00360 || (is_exec && !inc->exec_file)) { 00361 ast_includes_destroy(inc); 00362 return NULL; 00363 } 00364 00365 /* attach this new struct to the conf struct */ 00366 inc->next = conf->includes; 00367 conf->includes = inc; 00368 00369 return inc; 00370 }
void ast_include_rename | ( | struct ast_config * | conf, | |
const char * | from_file, | |||
const char * | to_file | |||
) |
Definition at line 372 of file config.c.
References ast_free, ast_strdup, ast_variable_destroy(), ast_variable_move(), ast_variable_new(), ast_variable::file, ast_category::file, ast_config_include::include_location_file, ast_config::includes, ast_category::last, ast_variable::name, ast_variable::next, ast_category::next, ast_config_include::next, ast_category::root, ast_config::root, str, and ast_variable::value.
Referenced by action_updateconfig().
00373 { 00374 struct ast_config_include *incl; 00375 struct ast_category *cat; 00376 char *str; 00377 00378 int from_len = strlen(from_file); 00379 int to_len = strlen(to_file); 00380 00381 if (strcmp(from_file, to_file) == 0) /* no use wasting time if the name is the same */ 00382 return; 00383 00384 /* the manager code allows you to read in one config file, then 00385 * write it back out under a different name. But, the new arrangement 00386 * ties output lines to the file name. So, before you try to write 00387 * the config file to disk, better riffle thru the data and make sure 00388 * the file names are changed. 00389 */ 00390 /* file names are on categories, includes (of course), and on variables. So, 00391 * traverse all this and swap names */ 00392 00393 for (incl = conf->includes; incl; incl=incl->next) { 00394 if (strcmp(incl->include_location_file,from_file) == 0) { 00395 if (from_len >= to_len) 00396 strcpy(incl->include_location_file, to_file); 00397 else { 00398 /* Keep the old filename if the allocation fails. */ 00399 str = ast_strdup(to_file); 00400 if (str) { 00401 ast_free(incl->include_location_file); 00402 incl->include_location_file = str; 00403 } 00404 } 00405 } 00406 } 00407 for (cat = conf->root; cat; cat = cat->next) { 00408 struct ast_variable **prev; 00409 struct ast_variable *v; 00410 struct ast_variable *new_var; 00411 00412 if (strcmp(cat->file,from_file) == 0) { 00413 if (from_len >= to_len) 00414 strcpy(cat->file, to_file); 00415 else { 00416 /* Keep the old filename if the allocation fails. */ 00417 str = ast_strdup(to_file); 00418 if (str) { 00419 ast_free(cat->file); 00420 cat->file = str; 00421 } 00422 } 00423 } 00424 for (prev = &cat->root, v = cat->root; v; prev = &v->next, v = v->next) { 00425 if (strcmp(v->file, from_file)) { 00426 continue; 00427 } 00428 00429 /* 00430 * Calculate actual space available. The file string is 00431 * intentionally stuffed before the name string just so we can 00432 * do this. 00433 */ 00434 if (to_len < v->name - v->file) { 00435 /* The new name will fit in the available space. */ 00436 str = (char *) v->file;/* Stupid compiler complains about discarding qualifiers even though I used a cast. */ 00437 strcpy(str, to_file);/* SAFE */ 00438 continue; 00439 } 00440 00441 /* Keep the old filename if the allocation fails. */ 00442 new_var = ast_variable_new(v->name, v->value, to_file); 00443 if (!new_var) { 00444 continue; 00445 } 00446 00447 /* Move items from the old list node to the replacement node. */ 00448 ast_variable_move(new_var, v); 00449 00450 /* Replace the old node in the list with the new node. */ 00451 new_var->next = v->next; 00452 if (cat->last == v) { 00453 cat->last = new_var; 00454 } 00455 *prev = new_var; 00456 00457 ast_variable_destroy(v); 00458 00459 v = new_var; 00460 } 00461 } 00462 }
AST_INLINE_API | ( | int | ast_rq_is_intrequire_type type | ) |
Check if require type is an integer type.
Remove standard encoding from realtime values, which ensures that a semicolon embedded within a single value is not treated upon retrieval as multiple values.
chunk | Data to be decoded |
struct ast_variable* ast_load_realtime | ( | const char * | family, | |
... | ||||
) | [read] |
Retrieve realtime configuration.
family | which family/config to lookup |
This will use builtin configuration backends to look up a particular entity in realtime and return a variable list of its parameters.
Definition at line 2382 of file config.c.
References ast_load_realtime_helper(), ast_strlen_zero(), ast_variable_destroy(), ast_variable::next, and ast_variable::value.
Referenced by conf_run(), copy_plain_file(), find_conf_realtime(), find_realtime(), find_realtime_gw(), find_user_realtime(), leave_queue(), load_realtime_queue(), local_ast_moh_start(), queue_function_queuewaitingcount(), realtime_alias(), realtime_peer(), realtime_peer_by_addr(), realtime_peer_by_name(), realtime_peer_get_sippeer_helper(), realtime_switch_common(), realtime_user(), and rt_extend_conf().
02383 { 02384 struct ast_variable *res; 02385 struct ast_variable *cur; 02386 struct ast_variable **prev; 02387 va_list ap; 02388 02389 va_start(ap, family); 02390 res = ast_load_realtime_helper(family, ap); 02391 va_end(ap); 02392 02393 /* Filter the list. */ 02394 prev = &res; 02395 cur = res; 02396 while (cur) { 02397 if (ast_strlen_zero(cur->value)) { 02398 /* Eliminate empty entries */ 02399 struct ast_variable *next; 02400 02401 next = cur->next; 02402 *prev = next; 02403 ast_variable_destroy(cur); 02404 cur = next; 02405 } else { 02406 /* Make blank entries empty and keep them. */ 02407 if (cur->value[0] == ' ' && cur->value[1] == '\0') { 02408 char *vptr = (char *) cur->value; 02409 02410 vptr[0] = '\0'; 02411 } 02412 02413 prev = &cur->next; 02414 cur = cur->next; 02415 } 02416 } 02417 return res; 02418 }
struct ast_variable* ast_load_realtime_all | ( | const char * | family, | |
... | ||||
) | [read] |
Definition at line 2370 of file config.c.
References ast_load_realtime_helper().
Referenced by cli_realtime_load(), function_realtime_read(), function_realtime_readdestroy(), and realtimefield_read().
02371 { 02372 struct ast_variable *res; 02373 va_list ap; 02374 02375 va_start(ap, family); 02376 res = ast_load_realtime_helper(family, ap); 02377 va_end(ap); 02378 02379 return res; 02380 }
struct ast_config* ast_load_realtime_multientry | ( | const char * | family, | |
... | ||||
) | [read] |
Retrieve realtime configuration.
family | which family/config to lookup |
This will use builtin configuration backends to look up a particular entity in realtime and return a variable list of its parameters. Unlike the ast_load_realtime, this function can return more than one entry and is thus stored inside a traditional ast_config structure rather than just returning a linked list of variables.
NULL | Error or no results returned |
Definition at line 2484 of file config.c.
References ast_config_destroy(), db, find_engine(), ast_config_engine::realtime_multi_func, ast_config::root, and table.
Referenced by __queues_show(), conf_exec(), find_realtime(), get_insecure_variable_from_sippeers(), get_insecure_variable_from_sipregs(), load_realtime_queue(), queues_data_provider_get(), realtime_directory(), realtime_switch_common(), show_users_realtime(), and update_realtime_members().
02485 { 02486 struct ast_config_engine *eng; 02487 char db[256]; 02488 char table[256]; 02489 struct ast_config *res = NULL; 02490 va_list ap; 02491 int i; 02492 02493 va_start(ap, family); 02494 for (i = 1; ; i++) { 02495 if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) { 02496 if (eng->realtime_multi_func && (res = eng->realtime_multi_func(db, table, ap))) { 02497 /* If we were returned an empty cfg, destroy it and return NULL */ 02498 if (!res->root) { 02499 ast_config_destroy(res); 02500 res = NULL; 02501 } 02502 break; 02503 } 02504 } else { 02505 break; 02506 } 02507 } 02508 va_end(ap); 02509 02510 return res; 02511 }
int ast_parse_arg | ( | const char * | arg, | |
enum ast_parse_flags | flags, | |||
void * | p_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. |
Examples of use: ast_parse_arg("223", PARSE_INT32|PARSE_IN_RANGE, &a, -1000, 1000); returns 0, a = 223 ast_parse_arg("22345", PARSE_INT32|PARSE_IN_RANGE|PARSE_DEFAULT, &a, 9999, 10, 100); returns 1, a = 9999 ast_parse_arg("22345ssf", PARSE_UINT32|PARSE_IN_RANGE, &b, 10, 100); returns 1, b unchanged ast_parse_arg("www.foo.biz:44", PARSE_INADDR, &sa); returns 0, sa contains address and port ast_parse_arg("www.foo.biz", PARSE_INADDR|PARSE_PORT_REQUIRE, &sa); returns 1 because port is missing, sa contains address
Definition at line 2639 of file config.c.
References ast_debug, ast_gethostbyname(), ast_inet_ntoa(), ast_skip_blanks(), ast_sockaddr_parse(), ast_sockaddr_stringify(), ast_strdupa, ast_strlen_zero(), errno, hp, INT32_MAX, INT32_MIN, PARSE_ADDR, 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 UINT32_MAX.
Referenced by __ast_http_load(), ast_tls_read_conf(), check_via_response(), gtalk_load_config(), and reload_config().
02641 { 02642 va_list ap; 02643 int error = 0; 02644 02645 va_start(ap, p_result); 02646 switch (flags & PARSE_TYPE) { 02647 case PARSE_INT32: 02648 { 02649 long int x = 0; 02650 int32_t *result = p_result; 02651 int32_t def = result ? *result : 0, high = INT32_MAX, low = INT32_MIN; 02652 char *endptr = NULL; 02653 02654 /* optional arguments: default value and/or (low, high) */ 02655 if (flags & PARSE_DEFAULT) { 02656 def = va_arg(ap, int32_t); 02657 } 02658 if (flags & (PARSE_IN_RANGE | PARSE_OUT_RANGE)) { 02659 low = va_arg(ap, int32_t); 02660 high = va_arg(ap, int32_t); 02661 } 02662 if (ast_strlen_zero(arg)) { 02663 error = 1; 02664 goto int32_done; 02665 } 02666 errno = 0; 02667 x = strtol(arg, &endptr, 0); 02668 if (*endptr || errno || x < INT32_MIN || x > INT32_MAX) { 02669 /* Parse error, or type out of int32_t bounds */ 02670 error = 1; 02671 goto int32_done; 02672 } 02673 error = (x < low) || (x > high); 02674 if (flags & PARSE_OUT_RANGE) { 02675 error = !error; 02676 } 02677 int32_done: 02678 if (result) { 02679 *result = error ? def : x; 02680 } 02681 02682 ast_debug(3, "extract int from [%s] in [%d, %d] gives [%ld](%d)\n", 02683 arg, low, high, result ? *result : x, error); 02684 break; 02685 } 02686 02687 case PARSE_UINT32: 02688 { 02689 unsigned long int x = 0; 02690 uint32_t *result = p_result; 02691 uint32_t def = result ? *result : 0, low = 0, high = UINT32_MAX; 02692 char *endptr = NULL; 02693 02694 /* optional argument: first default value, then range */ 02695 if (flags & PARSE_DEFAULT) { 02696 def = va_arg(ap, uint32_t); 02697 } 02698 if (flags & (PARSE_IN_RANGE|PARSE_OUT_RANGE)) { 02699 /* range requested, update bounds */ 02700 low = va_arg(ap, uint32_t); 02701 high = va_arg(ap, uint32_t); 02702 } 02703 02704 if (ast_strlen_zero(arg)) { 02705 error = 1; 02706 goto uint32_done; 02707 } 02708 /* strtoul will happilly and silently negate negative numbers */ 02709 arg = ast_skip_blanks(arg); 02710 if (*arg == '-') { 02711 error = 1; 02712 goto uint32_done; 02713 } 02714 errno = 0; 02715 x = strtoul(arg, &endptr, 0); 02716 if (*endptr || errno || x > UINT32_MAX) { 02717 error = 1; 02718 goto uint32_done; 02719 } 02720 error = (x < low) || (x > high); 02721 if (flags & PARSE_OUT_RANGE) { 02722 error = !error; 02723 } 02724 uint32_done: 02725 if (result) { 02726 *result = error ? def : x; 02727 } 02728 ast_debug(3, "extract uint from [%s] in [%u, %u] gives [%lu](%d)\n", 02729 arg, low, high, result ? *result : x, error); 02730 break; 02731 } 02732 02733 case PARSE_DOUBLE: 02734 { 02735 double *result = p_result; 02736 double x = 0, def = result ? *result : 0, low = -HUGE_VAL, high = HUGE_VAL; 02737 char *endptr = NULL; 02738 02739 /* optional argument: first default value, then range */ 02740 if (flags & PARSE_DEFAULT) { 02741 def = va_arg(ap, double); 02742 } 02743 if (flags & (PARSE_IN_RANGE | PARSE_OUT_RANGE)) { 02744 /* range requested, update bounds */ 02745 low = va_arg(ap, double); 02746 high = va_arg(ap, double); 02747 } 02748 if (ast_strlen_zero(arg)) { 02749 error = 1; 02750 goto double_done; 02751 } 02752 errno = 0; 02753 x = strtod(arg, &endptr); 02754 if (*endptr || errno == ERANGE) { 02755 error = 1; 02756 goto double_done; 02757 } 02758 error = (x < low) || (x > high); 02759 if (flags & PARSE_OUT_RANGE) { 02760 error = !error; 02761 } 02762 double_done: 02763 if (result) { 02764 *result = error ? def : x; 02765 } 02766 ast_debug(3, "extract double from [%s] in [%f, %f] gives [%f](%d)\n", 02767 arg, low, high, result ? *result : x, error); 02768 break; 02769 } 02770 case PARSE_ADDR: 02771 { 02772 struct ast_sockaddr *addr = (struct ast_sockaddr *)p_result; 02773 02774 if (!ast_sockaddr_parse(addr, arg, flags & PARSE_PORT_MASK)) { 02775 error = 1; 02776 } 02777 02778 ast_debug(3, "extract addr from %s gives %s(%d)\n", 02779 arg, ast_sockaddr_stringify(addr), error); 02780 02781 break; 02782 } 02783 case PARSE_INADDR: /* TODO Remove this (use PARSE_ADDR instead). */ 02784 { 02785 char *port, *buf; 02786 struct sockaddr_in _sa_buf; /* buffer for the result */ 02787 struct sockaddr_in *sa = p_result ? 02788 (struct sockaddr_in *)p_result : &_sa_buf; 02789 /* default is either the supplied value or the result itself */ 02790 struct sockaddr_in *def = (flags & PARSE_DEFAULT) ? 02791 va_arg(ap, struct sockaddr_in *) : sa; 02792 struct hostent *hp; 02793 struct ast_hostent ahp; 02794 02795 memset(&_sa_buf, '\0', sizeof(_sa_buf)); /* clear buffer */ 02796 /* duplicate the string to strip away the :port */ 02797 port = ast_strdupa(arg); 02798 buf = strsep(&port, ":"); 02799 sa->sin_family = AF_INET; /* assign family */ 02800 /* 02801 * honor the ports flag setting, assign default value 02802 * in case of errors or field unset. 02803 */ 02804 flags &= PARSE_PORT_MASK; /* the only flags left to process */ 02805 if (port) { 02806 if (flags == PARSE_PORT_FORBID) { 02807 error = 1; /* port was forbidden */ 02808 sa->sin_port = def->sin_port; 02809 } else if (flags == PARSE_PORT_IGNORE) 02810 sa->sin_port = def->sin_port; 02811 else /* accept or require */ 02812 sa->sin_port = htons(strtol(port, NULL, 0)); 02813 } else { 02814 sa->sin_port = def->sin_port; 02815 if (flags == PARSE_PORT_REQUIRE) 02816 error = 1; 02817 } 02818 /* Now deal with host part, even if we have errors before. */ 02819 hp = ast_gethostbyname(buf, &ahp); 02820 if (hp) /* resolved successfully */ 02821 memcpy(&sa->sin_addr, hp->h_addr, sizeof(sa->sin_addr)); 02822 else { 02823 error = 1; 02824 sa->sin_addr = def->sin_addr; 02825 } 02826 ast_debug(3, 02827 "extract inaddr from [%s] gives [%s:%d](%d)\n", 02828 arg, ast_inet_ntoa(sa->sin_addr), 02829 ntohs(sa->sin_port), error); 02830 break; 02831 } 02832 } 02833 va_end(ap); 02834 return error; 02835 }
int ast_realtime_enabled | ( | void | ) |
Check if there's any realtime engines loaded.
Definition at line 2435 of file config.c.
References config_maps.
Referenced by action_coresettings(), ast_check_realtime(), and handle_show_settings().
02436 { 02437 return config_maps ? 1 : 0; 02438 }
char* ast_realtime_encode_chunk | ( | struct ast_str ** | dest, | |
ssize_t | maxlen, | |||
const char * | chunk | |||
) |
Encodes a chunk of data for realtime.
dest | Destination buffer | |
maxlen | Length passed through to ast_str_* functions | |
chunk | Source data to be encoded |
Definition at line 2619 of file config.c.
References ast_str_append(), ast_str_buffer(), ast_str_reset(), and ast_str_set().
02620 { 02621 if (!strchr(chunk, ';') && !strchr(chunk, '^')) { 02622 ast_str_set(dest, maxlen, "%s", chunk); 02623 } else { 02624 ast_str_reset(*dest); 02625 for (; *chunk; chunk++) { 02626 if (strchr(";^", *chunk)) { 02627 ast_str_append(dest, maxlen, "^%02hhX", *chunk); 02628 } else { 02629 ast_str_append(dest, maxlen, "%c", *chunk); 02630 } 02631 } 02632 } 02633 return ast_str_buffer(*dest); 02634 }
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.
The arguments are specified in groups of 3: column name, column type, and column size. The column types are specified as integer constants, defined by the enum require_type. Note that the size is specified as the number of equivalent character fields that a field may take up, even if a field is otherwise specified as an integer type. This is due to the fact that some fields have historically been specified as character types, even if they contained integer values.
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 2440 of file config.c.
References db, find_engine(), ast_config_engine::require_func, and table.
Referenced by ast_queue_log(), change_password_realtime(), conf_run(), load_module(), and logger_queue_rt_start().
02441 { 02442 struct ast_config_engine *eng; 02443 char db[256]; 02444 char table[256]; 02445 va_list ap; 02446 int res = -1, i; 02447 02448 va_start(ap, family); 02449 for (i = 1; ; i++) { 02450 if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) { 02451 /* If the require succeeds, it returns 0. */ 02452 if (eng->require_func && !(res = eng->require_func(db, table, ap))) { 02453 break; 02454 } 02455 } else { 02456 break; 02457 } 02458 } 02459 va_end(ap); 02460 02461 return res; 02462 }
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 2560 of file config.c.
References db, find_engine(), ast_config_engine::store_func, and table.
Referenced by ast_queue_log(), cli_realtime_store(), copy_plain_file(), function_realtime_store(), and leave_voicemail().
02561 { 02562 struct ast_config_engine *eng; 02563 int res = -1, i; 02564 char db[256]; 02565 char table[256]; 02566 va_list ap; 02567 02568 va_start(ap, family); 02569 for (i = 1; ; i++) { 02570 if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) { 02571 /* If the store succeeds, it returns 0. */ 02572 if (eng->store_func && !(res = eng->store_func(db, table, ap))) { 02573 break; 02574 } 02575 } else { 02576 break; 02577 } 02578 } 02579 va_end(ap); 02580 02581 return res; 02582 }
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 2464 of file config.c.
References db, find_engine(), table, and ast_config_engine::unload_func.
Referenced by __unload_module(), load_config(), logger_queue_init(), reload(), reload_config(), reload_logger(), and unload_module().
02465 { 02466 struct ast_config_engine *eng; 02467 char db[256]; 02468 char table[256]; 02469 int res = -1, i; 02470 02471 for (i = 1; ; i++) { 02472 if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) { 02473 if (eng->unload_func) { 02474 /* Do this for ALL engines */ 02475 res = eng->unload_func(db, table); 02476 } 02477 } else { 02478 break; 02479 } 02480 } 02481 return res; 02482 }
int ast_update2_realtime | ( | const char * | family, | |
... | ||||
) |
Update realtime configuration.
family | which family/config to be updated |
This function is used to update a parameter in realtime configuration space. It includes the ability to lookup a row based upon multiple key criteria. As a result, this function includes two sentinel values, one to terminate lookup values and the other to terminate the listing of fields to update.
Definition at line 2537 of file config.c.
References db, find_engine(), table, and ast_config_engine::update2_func.
Referenced by change_password_realtime(), and cli_realtime_update2().
02538 { 02539 struct ast_config_engine *eng; 02540 int res = -1, i; 02541 char db[256]; 02542 char table[256]; 02543 va_list ap; 02544 02545 va_start(ap, family); 02546 for (i = 1; ; i++) { 02547 if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) { 02548 if (eng->update2_func && !(res = eng->update2_func(db, table, ap))) { 02549 break; 02550 } 02551 } else { 02552 break; 02553 } 02554 } 02555 va_end(ap); 02556 02557 return res; 02558 }
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 2513 of file config.c.
References db, find_engine(), table, and ast_config_engine::update_func.
Referenced by cli_realtime_update(), conf_run(), destroy_association(), function_realtime_write(), handle_response_peerpoke(), leave_voicemail(), realtime_update_peer(), rename_file(), rt_extend_conf(), sip_poke_noanswer(), and update_realtime_member_field().
02514 { 02515 struct ast_config_engine *eng; 02516 int res = -1, i; 02517 char db[256]; 02518 char table[256]; 02519 va_list ap; 02520 02521 va_start(ap, lookup); 02522 for (i = 1; ; i++) { 02523 if ((eng = find_engine(family, i, db, sizeof(db), table, sizeof(table)))) { 02524 /* If the update succeeds, it returns 0. */ 02525 if (eng->update_func && !(res = eng->update_func(db, table, keyfield, lookup, ap))) { 02526 break; 02527 } 02528 } else { 02529 break; 02530 } 02531 } 02532 va_end(ap); 02533 02534 return res; 02535 }
void ast_variable_append | ( | struct ast_category * | category, | |
struct ast_variable * | variable | |||
) |
Definition at line 475 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(), vm_change_password(), and write_password_to_file().
struct ast_variable* ast_variable_browse | ( | const struct ast_config * | config, | |
const char * | category | |||
) | [read] |
Goes through variables.
Somewhat similar in intent as the ast_category_browse. List variables of config file category
ast_variable | list on success | |
NULL | on failure |
Definition at line 565 of file config.c.
References ast_category_get(), ast_config::last_browse, ast_category::name, and ast_category::root.
Referenced by __ast_http_load(), __ast_http_post_load(), __init_manager(), _dsp_init(), action_getconfig(), action_getconfigjson(), actual_load_config(), adsi_load(), aji_load_config(), ast_cli_perms_init(), AST_LIST_HEAD_NOLOCK(), ast_plc_reload(), ast_readconfig(), ast_variable_retrieve(), build_calendar(), build_device(), build_event_channel(), caldav_load_calendar(), conf_exec(), config_load(), config_module(), do_say(), ewscal_load_calendar(), exchangecal_load_calendar(), find_conf(), gtalk_load_config(), handle_cli_dialplan_save(), iax_template_parse(), ical_load_calendar(), init_logger_chain(), jingle_load_config(), load_config(), load_module(), load_modules(), load_moh_classes(), load_odbc_config(), load_pktccops_config(), misdn_cfg_init(), odbc_load_module(), osp_create_provider(), parse_config(), parse_tone_zone(), pbx_load_config(), process_config(), read_agent_config(), read_config_maps(), reload(), reload_config(), reload_followme(), reload_module(), reload_queue_rules(), reload_single_queue(), run_startup_commands(), set_config(), setup_dahdi_int(), show_users_realtime(), sip_cli_notify(), sla_build_station(), sla_build_trunk(), smdi_load(), store_config(), and tds_load_module().
00566 { 00567 struct ast_category *cat = NULL; 00568 00569 if (!category) { 00570 return NULL; 00571 } 00572 00573 if (config->last_browse && (config->last_browse->name == category)) { 00574 cat = config->last_browse; 00575 } else { 00576 cat = ast_category_get(config, category); 00577 } 00578 00579 return (cat) ? cat->root : NULL; 00580 }
int ast_variable_delete | ( | struct ast_category * | category, | |
const char * | variable, | |||
const char * | match, | |||
const char * | line | |||
) |
Definition at line 861 of file config.c.
References ast_strlen_zero(), ast_variable_destroy(), ast_category::last, ast_variable::name, ast_variable::next, ast_category::root, and ast_variable::value.
Referenced by handle_updates().
00862 { 00863 struct ast_variable *cur, *prev=NULL, *curn; 00864 int res = -1; 00865 int num_item = 0; 00866 int req_item; 00867 00868 req_item = -1; 00869 if (!ast_strlen_zero(line)) { 00870 /* Requesting to delete by item number. */ 00871 if (sscanf(line, "%30d", &req_item) != 1 00872 || req_item < 0) { 00873 /* Invalid item number to delete. */ 00874 return -1; 00875 } 00876 } 00877 00878 prev = NULL; 00879 cur = category->root; 00880 while (cur) { 00881 curn = cur->next; 00882 /* Delete by item number or by variable name with optional value. */ 00883 if ((0 <= req_item && num_item == req_item) 00884 || (req_item < 0 && !strcasecmp(cur->name, variable) 00885 && (ast_strlen_zero(match) || !strcasecmp(cur->value, match)))) { 00886 if (prev) { 00887 prev->next = cur->next; 00888 if (cur == category->last) 00889 category->last = prev; 00890 } else { 00891 category->root = cur->next; 00892 if (cur == category->last) 00893 category->last = NULL; 00894 } 00895 ast_variable_destroy(cur); 00896 res = 0; 00897 } else 00898 prev = cur; 00899 00900 cur = curn; 00901 ++num_item; 00902 } 00903 return res; 00904 }
void ast_variable_insert | ( | struct ast_category * | category, | |
struct ast_variable * | variable, | |||
const char * | line | |||
) |
Definition at line 488 of file config.c.
References ast_variable::next, and ast_category::root.
Referenced by handle_updates().
00489 { 00490 struct ast_variable *cur = category->root; 00491 int lineno; 00492 int insertline; 00493 00494 if (!variable || sscanf(line, "%30d", &insertline) != 1) { 00495 return; 00496 } 00497 if (!insertline) { 00498 variable->next = category->root; 00499 category->root = variable; 00500 } else { 00501 for (lineno = 1; lineno < insertline; lineno++) { 00502 cur = cur->next; 00503 if (!cur->next) { 00504 break; 00505 } 00506 } 00507 variable->next = cur->next; 00508 cur->next = variable; 00509 } 00510 }
struct ast_variable* ast_variable_new | ( | const char * | name, | |
const char * | value, | |||
const char * | filename | |||
) | [read] |
Definition at line 270 of file config.c.
References __ast_calloc(), ast_calloc, ast_variable::file, MIN_VARIABLE_FNAME_SPACE, ast_variable::name, ast_variable::stuff, and ast_variable::value.
Referenced by add_cfg_entry(), add_rt_cfg_entry(), add_rt_multi_cfg_entry(), add_var(), apply_outgoing(), ast_channeltype_list(), ast_http_get_post_vars(), ast_include_rename(), ast_variable_update(), ast_variables_dup(), build_user(), check_access(), config_curl(), config_ldap(), config_odbc(), config_pgsql(), copy_vars(), create_vmaccount(), dup_vars(), handle_updates(), handle_uri(), httpd_helper_thread(), iax_parse_ies(), ldap_table_config_add_attribute(), man_do_variable_value(), manager_sipnotify(), mkintf(), parkandannounce_exec(), parse_cookies(), process_dahdi(), 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(), sip_cli_notify(), variable_clone(), vm_change_password(), and write_password_to_file().
00272 { 00273 struct ast_variable *variable; 00274 int name_len = strlen(name) + 1; 00275 int val_len = strlen(value) + 1; 00276 int fn_len = strlen(filename) + 1; 00277 00278 /* Ensure a minimum length in case the filename is changed later. */ 00279 if (fn_len < MIN_VARIABLE_FNAME_SPACE) { 00280 fn_len = MIN_VARIABLE_FNAME_SPACE; 00281 } 00282 00283 if ( 00284 #ifdef MALLOC_DEBUG 00285 (variable = __ast_calloc(1, fn_len + name_len + val_len + sizeof(*variable), file, lineno, func)) 00286 #else 00287 (variable = ast_calloc(1, fn_len + name_len + val_len + sizeof(*variable))) 00288 #endif 00289 ) { 00290 char *dst = variable->stuff; /* writable space starts here */ 00291 00292 /* Put file first so ast_include_rename() can calculate space available. */ 00293 variable->file = strcpy(dst, filename); 00294 dst += fn_len; 00295 variable->name = strcpy(dst, name); 00296 dst += name_len; 00297 variable->value = strcpy(dst, value); 00298 } 00299 return variable; 00300 }
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 593 of file config.c.
References ast_variable_browse(), ast_variable::name, ast_category::next, ast_variable::next, ast_category::root, ast_config::root, and ast_variable::value.
Referenced by __ast_udptl_reload(), __init_manager(), actual_load_config(), advanced_options(), aji_load_config(), ast_config_option(), AST_LIST_HEAD_NOLOCK(), build_extension(), conf_exec(), config_function_read(), config_module(), directory_exec(), do_reload(), festival_exec(), find_queue_by_name_rt(), find_realtime(), get_insecure_variable_from_config(), get_insecure_variable_from_sipregs(), gtalk_load_config(), iax_template_parse(), init_acf_query(), init_logger_chain(), initialize_cc_max_requests(), jingle_load_config(), load_config(), load_config_meetme(), load_indications(), load_module(), load_modules(), load_tech_calendars(), make_email_file(), odbc_load_module(), osp_load(), parse_config(), pbx_load_config(), pbx_load_users(), play_message(), prep_email_sub_vars(), private_enum_init(), queue_set_global_params(), read_agent_config(), read_password_from_file(), realtime_directory(), reload_config(), reload_followme(), reload_single_queue(), rtp_reload(), search_directory(), set_config(), setup_dahdi_int(), sla_build_station(), sla_build_trunk(), sla_load_config(), tds_load_module(), update_realtime_members(), vm_change_password(), and vm_forwardoptions().
00594 { 00595 struct ast_variable *v; 00596 00597 if (category) { 00598 for (v = ast_variable_browse(config, category); v; v = v->next) { 00599 if (!strcasecmp(variable, v->name)) { 00600 return v->value; 00601 } 00602 } 00603 } else { 00604 struct ast_category *cat; 00605 00606 for (cat = config->root; cat; cat = cat->next) { 00607 for (v = cat->root; v; v = v->next) { 00608 if (!strcasecmp(variable, v->name)) { 00609 return v->value; 00610 } 00611 } 00612 } 00613 } 00614 00615 return NULL; 00616 }
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 906 of file config.c.
References ast_strlen_zero(), ast_variable_destroy(), ast_variable_move(), ast_variable_new(), ast_variable::file, ast_category::last, ast_variable::name, ast_variable::next, ast_category::root, and ast_variable::value.
Referenced by handle_updates(), process_text_line(), vm_change_password(), and vm_forwardoptions().
00908 { 00909 struct ast_variable *cur, *prev=NULL, *newer=NULL; 00910 00911 for (cur = category->root; cur; prev = cur, cur = cur->next) { 00912 if (strcasecmp(cur->name, variable) || 00913 (!ast_strlen_zero(match) && strcasecmp(cur->value, match))) 00914 continue; 00915 00916 if (!(newer = ast_variable_new(variable, value, cur->file))) 00917 return -1; 00918 00919 ast_variable_move(newer, cur); 00920 newer->object = newer->object || object; 00921 00922 /* Replace the old node in the list with the new node. */ 00923 newer->next = cur->next; 00924 if (prev) 00925 prev->next = newer; 00926 else 00927 category->root = newer; 00928 if (category->last == cur) 00929 category->last = newer; 00930 00931 ast_variable_destroy(cur); 00932 00933 return 0; 00934 } 00935 00936 /* Could not find variable to update */ 00937 return -1; 00938 }
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 554 of file config.c.
References ast_variable_destroy(), and ast_variable::next.
Referenced by __sip_destroy(), action_originate(), ast_category_destroy(), ast_category_empty(), ast_http_get_cookies(), ast_http_manid_from_vars(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_var_channel_types(), ast_var_channel_types_table(), ast_variables_dup(), auth_http_callback(), build_gateway(), build_peer(), build_user(), check_peer_ok(), cli_realtime_load(), conf_run(), copy_plain_file(), destroy_dahdi_pvt(), destroy_endpoint(), destroy_fast_originate_helper(), dup_vars(), find_conf_realtime(), find_realtime(), find_realtime_gw(), find_user_realtime(), free_entry(), free_outgoing(), free_user(), function_realtime_read(), function_realtime_readdestroy(), generic_http_callback(), get_insecure_variable_from_sipregs(), handle_uri(), http_post_callback(), httpd_helper_thread(), httpstatus_callback(), ldap_loadentry(), leave_queue(), load_realtime_queue(), local_ast_moh_start(), manager_sipnotify(), mkintf(), parkandannounce_exec(), process_dahdi(), pvt_destructor(), queue_function_queuewaitingcount(), realtime_alias(), realtime_canmatch(), realtime_common(), realtime_exec(), realtime_exists(), realtime_handler(), realtime_ldap_base_ap(), realtime_ldap_result_to_vars(), realtime_matchmore(), realtime_odbc(), realtime_peer(), realtime_peer_by_addr(), realtime_peer_by_name(), realtime_peer_get_sippeer_helper(), realtime_user(), realtimefield_read(), rt_extend_conf(), sip_destroy_peer(), socket_process(), table_configs_free(), and user_destructor().
00555 { 00556 struct ast_variable *vn; 00557 00558 while (v) { 00559 vn = v; 00560 v = v->next; 00561 ast_variable_destroy(vn); 00562 } 00563 }
struct ast_variable* ast_variables_dup | ( | struct ast_variable * | var | ) | [read] |
Duplicate variable list.
var | the linked list of variables to clone |
Definition at line 532 of file config.c.
References ast_variable_new(), ast_variables_destroy(), ast_variable::file, ast_variable::name, ast_variable::next, and ast_variable::value.
Referenced by get_insecure_variable_from_sippeers(), and get_insecure_variable_from_sipregs().
00533 { 00534 struct ast_variable *cloned; 00535 struct ast_variable *tmp; 00536 00537 if (!(cloned = ast_variable_new(var->name, var->value, var->file))) { 00538 return NULL; 00539 } 00540 00541 tmp = cloned; 00542 00543 while ((var = var->next)) { 00544 if (!(tmp->next = ast_variable_new(var->name, var->value, var->file))) { 00545 ast_variables_destroy(cloned); 00546 return NULL; 00547 } 00548 tmp = tmp->next; 00549 } 00550 00551 return cloned; 00552 }
int config_text_file_save | ( | const char * | filename, | |
const struct ast_config * | cfg, | |||
const char * | generator | |||
) |
Definition at line 1821 of file config.c.
References ast_config_text_file_save().
01822 { 01823 return ast_config_text_file_save(configfile, cfg, generator); 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 2131 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(), clear_config_maps(), config, CONFIG_FLAG_NOREALTIME, CONFIG_STATUS_FILEINVALID, LOG_ERROR, LOG_WARNING, ast_config::max_include_level, ast_variable::name, ast_variable::next, table, and ast_variable::value.
Referenced by main().
02132 { 02133 struct ast_config *config, *configtmp; 02134 struct ast_variable *v; 02135 char *driver, *table, *database, *textpri, *stringp, *tmp; 02136 struct ast_flags flags = { CONFIG_FLAG_NOREALTIME }; 02137 int pri; 02138 02139 clear_config_maps(); 02140 02141 configtmp = ast_config_new(); 02142 if (!configtmp) { 02143 ast_log(LOG_ERROR, "Unable to allocate memory for new config\n"); 02144 return -1; 02145 } 02146 configtmp->max_include_level = 1; 02147 config = ast_config_internal_load(extconfig_conf, configtmp, flags, "", "extconfig"); 02148 if (config == CONFIG_STATUS_FILEINVALID) { 02149 return -1; 02150 } else if (!config) { 02151 ast_config_destroy(configtmp); 02152 return 0; 02153 } 02154 02155 for (v = ast_variable_browse(config, "settings"); v; v = v->next) { 02156 char buf[512]; 02157 ast_copy_string(buf, v->value, sizeof(buf)); 02158 stringp = buf; 02159 driver = strsep(&stringp, ","); 02160 02161 if ((tmp = strchr(stringp, '\"'))) 02162 stringp = tmp; 02163 02164 /* check if the database text starts with a double quote */ 02165 if (*stringp == '"') { 02166 stringp++; 02167 database = strsep(&stringp, "\""); 02168 strsep(&stringp, ","); 02169 } else { 02170 /* apparently this text has no quotes */ 02171 database = strsep(&stringp, ","); 02172 } 02173 02174 table = strsep(&stringp, ","); 02175 textpri = strsep(&stringp, ","); 02176 if (!textpri || !(pri = atoi(textpri))) { 02177 pri = 1; 02178 } 02179 02180 if (!strcmp(v->name, extconfig_conf)) { 02181 ast_log(LOG_WARNING, "Cannot bind '%s'!\n", extconfig_conf); 02182 continue; 02183 } 02184 02185 if (!strcmp(v->name, "asterisk.conf")) { 02186 ast_log(LOG_WARNING, "Cannot bind 'asterisk.conf'!\n"); 02187 continue; 02188 } 02189 02190 if (!strcmp(v->name, "logger.conf")) { 02191 ast_log(LOG_WARNING, "Cannot bind 'logger.conf'!\n"); 02192 continue; 02193 } 02194 02195 if (!driver || !database) 02196 continue; 02197 if (!strcasecmp(v->name, "sipfriends")) { 02198 ast_log(LOG_WARNING, "The 'sipfriends' table is obsolete, update your config to use sippeers instead.\n"); 02199 append_mapping("sippeers", driver, database, table ? table : "sipfriends", pri); 02200 } else if (!strcasecmp(v->name, "iaxfriends")) { 02201 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"); 02202 append_mapping("iaxusers", driver, database, table ? table : "iaxfriends", pri); 02203 append_mapping("iaxpeers", driver, database, table ? table : "iaxfriends", pri); 02204 } else 02205 append_mapping(v->name, driver, database, table, pri); 02206 } 02207 02208 ast_config_destroy(config); 02209 return 0; 02210 }
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 2979 of file config.c.
References ARRAY_LEN, ast_cli_register_multiple(), ast_register_atexit(), and config_shutdown().
Referenced by main().
02980 { 02981 ast_cli_register_multiple(cli_config, ARRAY_LEN(cli_config)); 02982 ast_register_atexit(config_shutdown); 02983 return 0; 02984 }