#include "asterisk/utils.h"
#include "asterisk/inline_api.h"
Include dependency graph for config.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Data Structures | |
| struct | ast_config_engine |
| Configuration engine structure, used to define realtime drivers. More... | |
| struct | ast_variable |
| Structure for variables, used for configurations and for channel variables. More... | |
Defines | |
| #define | ast_config_load(filename, flags) ast_config_load2(filename, AST_MODULE, flags) |
| #define | CONFIG_STATUS_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, if (__dst) ast_free(__dst); __dst = ast_strdup(__val)) |
| #define | CV_END } while (0) |
| close a variable parsing block | |
| #define | CV_F(__pattern, __body) if (!strcasecmp((__var), __pattern)) { __body; break; } |
| call a generic function if the name matches. | |
| #define | CV_START(__in_var, __in_val) |
| the macro to open a block for variable parsing | |
| #define | CV_STR(__x, __dst) CV_F(__x, ast_copy_string(__dst, __val, sizeof(__dst))) |
| #define | CV_STRFIELD(__x, __obj, __field) CV_F(__x, ast_string_field_set(__obj, __field, __val)) |
| #define | CV_UINT(__x, __dst) CV_F(__x, (__dst) = strtoul(__val, NULL, 0) ) |
Typedefs | |
| typedef ast_config * | config_load_func (const char *database, const char *table, const char *configfile, struct ast_config *config, struct ast_flags flags, const char *suggested_include_file, const char *who_asked) |
| typedef int | realtime_destroy (const char *database, const char *table, const char *keyfield, const char *entity, va_list ap) |
| typedef ast_config * | realtime_multi_get (const char *database, const char *table, va_list ap) |
| typedef int | realtime_require (const char *database, const char *table, va_list ap) |
| Function pointer called to ensure database schema is properly configured for realtime use. | |
| typedef int | realtime_store (const char *database, const char *table, va_list ap) |
| typedef int | realtime_unload (const char *database, const char *table) |
| Function pointer called to clear the database cache and free resources used for such. | |
| typedef int | realtime_update (const char *database, const char *table, const char *keyfield, const char *entity, va_list ap) |
| typedef int | realtime_update2 (const char *database, const char *table, va_list ap) |
| typedef ast_variable * | realtime_var_get (const char *database, const char *table, va_list ap) |
Enumerations | |
| enum | { CONFIG_FLAG_WITHCOMMENTS = (1 << 0), CONFIG_FLAG_FILEUNCHANGED = (1 << 1), CONFIG_FLAG_NOCACHE = (1 << 2) } |
| enum | ast_parse_flags { PARSE_TYPE = 0x000f, PARSE_INT32 = 0x0001, PARSE_UINT32 = 0x0002, PARSE_DOUBLE = 0x0003, PARSE_INADDR = 0x000f, PARSE_DEFAULT = 0x0010, PARSE_IN_RANGE = 0x0020, PARSE_OUT_RANGE = 0x0040, PARSE_PORT_MASK = 0x0300, PARSE_PORT_IGNORE = 0x0100, PARSE_PORT_REQUIRE = 0x0200, PARSE_PORT_FORBID = 0x0300 } |
| Support code to parse config file arguments. More... | |
| enum | require_type { RQ_INTEGER1, RQ_UINTEGER1, RQ_INTEGER2, RQ_UINTEGER2, RQ_INTEGER3, RQ_UINTEGER3, RQ_INTEGER4, RQ_UINTEGER4, RQ_INTEGER8, RQ_UINTEGER8, RQ_CHAR, RQ_FLOAT, RQ_DATE, RQ_DATETIME } |
| Types used in ast_realtime_require_field. More... | |
Functions | |
| void | ast_category_append (struct ast_config *config, struct ast_category *cat) |
| char * | ast_category_browse (struct ast_config *config, const char *prev) |
| Goes through categories. | |
| int | ast_category_delete (struct ast_config *cfg, const char *category) |
| void | ast_category_destroy (struct ast_category *cat) |
| ast_variable * | ast_category_detach_variables (struct ast_category *cat) |
| int | ast_category_empty (struct ast_config *cfg, const char *category) |
| Removes and destroys all variables within a category. | |
| int | ast_category_exist (const struct ast_config *config, const char *category_name) |
| Check for category duplicates. | |
| ast_variable * | ast_category_first (struct ast_category *cat) |
| given a pointer to a category, return the root variable. This is equivalent to ast_variable_browse(), but more efficient if we already have the struct ast_category * (e.g. from ast_category_get()) | |
| ast_category * | ast_category_get (const struct ast_config *config, const char *category_name) |
| Retrieve a category if it exists. | |
| void | ast_category_insert (struct ast_config *config, struct ast_category *cat, const char *match) |
| Inserts new category. | |
| ast_category * | ast_category_new (const char *name, const char *in_file, int lineno) |
| Create a category structure. | |
| void | ast_category_rename (struct ast_category *cat, const char *name) |
| ast_variable * | ast_category_root (struct ast_config *config, char *cat) |
| returns the root ast_variable of a config | |
| int | ast_check_realtime (const char *family) |
| Check if realtime engine is configured for family. | |
| void | ast_config_destroy (struct ast_config *config) |
| Destroys a config. | |
| int | ast_config_engine_deregister (struct ast_config_engine *del) |
| Deregister config engine. | |
| int | ast_config_engine_register (struct ast_config_engine *newconfig) |
| Register config engine. | |
| ast_category * | ast_config_get_current_category (const struct ast_config *cfg) |
| Retrieve the current category name being built. API for backend configuration engines while building a configuration set. | |
| ast_config * | ast_config_internal_load (const char *configfile, struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl_file, const char *who_asked) |
| ast_config * | ast_config_load2 (const char *filename, const char *who_asked, struct ast_flags flags) |
| Load a config file. | |
| ast_config * | ast_config_new (void) |
| Create a new base configuration structure. | |
| const char * | ast_config_option (struct ast_config *cfg, const char *cat, const char *var) |
Retrieve a configuration variable within the configuration set. Retrieves the named variable var within category cat of configuration set cfg. If not found, attempts to retrieve the named variable var from within category general. | |
| void | ast_config_set_current_category (struct ast_config *cfg, const struct ast_category *cat) |
| Set the category within the configuration as being current. API for backend configuration engines while building a configuration set. | |
| int | ast_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. | |
| ast_config_include * | ast_include_find (struct ast_config *conf, const char *included_file) |
| ast_config_include * | ast_include_new (struct ast_config *conf, const char *from_file, const char *included_file, int is_exec, const char *exec_file, int from_lineno, char *real_included_file_name, int real_included_file_name_size) |
| void | ast_include_rename (struct ast_config *conf, const char *from_file, const char *to_file) |
| ast_variable * | ast_load_realtime (const char *family,...) attribute_sentinel |
| Retrieve realtime configuration. | |
| ast_variable * | ast_load_realtime_all (const char *family,...) attribute_sentinel |
| ast_config * | ast_load_realtime_multientry (const char *family,...) attribute_sentinel |
| Retrieve realtime configuration. | |
| int | ast_parse_arg (const char *arg, enum ast_parse_flags flags, void *result,...) |
| The argument parsing routine. | |
| int | ast_realtime_enabled (void) |
| Check if there's any realtime engines loaded. | |
| int | ast_realtime_require_field (const char *family,...) attribute_sentinel |
| Inform realtime what fields that may be stored. | |
| int | ast_rq_is_int (require_type type) |
| Check if require type is an integer type. | |
| int | ast_store_realtime (const char *family,...) attribute_sentinel |
| Create realtime configuration. | |
| int | ast_unload_realtime (const char *family) |
| Release any resources cached for a realtime family. | |
| int | ast_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) |
| ast_variable * | ast_variable_browse (const struct ast_config *config, const char *category) |
| Goes through variables Somewhat similar in intent as the ast_category_browse. List variables of config file category. | |
| int | ast_variable_delete (struct ast_category *category, const char *variable, const char *match, const char *line) |
| void | ast_variable_insert (struct ast_category *category, struct ast_variable *variable, const char *line) |
| ast_variable * | ast_variable_new (const char *name, const char *value, const char *filename) |
| const char * | ast_variable_retrieve (const struct ast_config *config, const char *category, const char *variable) |
| Gets a variable. | |
| int | ast_variable_update (struct ast_category *category, const char *variable, const char *value, const char *match, unsigned int object) |
| Update variable value within a config. | |
| void | ast_variables_destroy (struct ast_variable *var) |
| Free variable list. | |
| int | config_text_file_save (const char *filename, const struct ast_config *cfg, const char *generator) |
| int | read_config_maps (void) |
| Exposed re-initialization method for core process This method is intended for use only with the core re-initialization and is not designed to be called from any user applications. | |
| int | register_config_cli (void) |
| Exposed initialization method for core process This method is intended for use only with the core initialization and is not designed to be called from any user applications. | |
Definition in file config.h.
| #define ast_config_load | ( | filename, | |||
| flags | ) | ast_config_load2(filename, AST_MODULE, flags) |
Definition at line 139 of file config.h.
Referenced by adsi_load(), advanced_options(), aji_load_config(), 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_rpt_vars(), make_email_file(), node_lookup(), odbc_load_module(), osp_load(), parse_config(), pbx_load_config(), pbx_load_users(), play_message(), prep_email_sub_vars(), read_agent_config(), realtime_directory(), reload(), reload_config(), reload_followme(), reload_queue_rules(), reload_queues(), rpt_master(), set_config(), setup_dahdi(), sla_load_config(), smdi_load(), store_config(), tds_load_module(), vm_change_password(), and vm_forwardoptions().
| #define CONFIG_STATUS_FILEINVALID (void *)-2 |
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(), advanced_options(), aji_load_config(), ast_config_internal_load(), ast_config_load2(), ast_readconfig(), ast_xmldoc_load_documentation(), 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(), jingle_load_config(), load_config(), load_config_meetme(), load_indications(), load_module(), load_modules(), load_moh_classes(), load_odbc_config(), load_rpt_vars(), misdn_cfg_init(), node_lookup(), odbc_load_module(), osp_load(), parse_config(), pbx_load_config(), play_message(), private_enum_init(), read_agent_config(), realtime_directory(), reload(), reload_config(), reload_followme(), reload_queue_rules(), reload_queues(), rpt_master(), rtp_reload(), run_startup_commands(), set_config(), setup_dahdi(), sla_load_config(), smdi_load(), store_config(), tds_load_module(), vm_change_password(), and vm_forwardoptions().
| #define CONFIG_STATUS_FILEMISSING (void *)0 |
Definition at line 48 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_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 49 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_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(), 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 581 of file config.h.
Referenced by store_config_core().
| #define CV_DSTR | ( | __x, | |||
| __dst | ) | CV_F(__x, if (__dst) ast_free(__dst); __dst = ast_strdup(__val)) |
| #define CV_END } while (0) |
close a variable parsing block
Definition at line 573 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 576 of file config.h.
Referenced by store_config_core(), and store_config_tone_zone().
| #define CV_START | ( | __in_var, | |||
| __in_val | ) |
Value:
do { \ const char *__var = __in_var; \ const char *__val = __in_val;
Definition at line 567 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 583 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)) |
| #define CV_UINT | ( | __x, | |||
| __dst | ) | CV_F(__x, (__dst) = strtoul(__val, NULL, 0) ) |
| typedef struct ast_config* config_load_func(const char *database, const char *table, const char *configfile, struct ast_config *config, struct ast_flags flags, const char *suggested_include_file, const char *who_asked) |
| typedef int realtime_destroy(const char *database, const char *table, const char *keyfield, const char *entity, va_list ap) |
| typedef struct ast_config* realtime_multi_get(const char *database, const char *table, va_list ap) |
| typedef int realtime_require(const char *database, const char *table, va_list ap) |
| typedef int realtime_store(const char *database, const char *table, va_list ap) |
| typedef int realtime_unload(const char *database, const char *table) |
| typedef int realtime_update(const char *database, const char *table, const char *keyfield, const char *entity, va_list ap) |
| typedef 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 };
| enum ast_parse_flags |
Support code to parse config file arguments.
The function ast_parse_arg() provides a generic interface to parse strings (e.g. numbers, network addresses and so on) in a flexible way, e.g. by doing proper error and bound checks, provide default values, and so on. The function (described later) takes a string as an argument, a set of flags to specify the result format and checks to perform, a pointer to the result, and optionally some additional arguments. It returns 0 on success, != 0 otherwise.
| PARSE_TYPE | |
| PARSE_INT32 | |
| PARSE_UINT32 | |
| PARSE_DOUBLE | |
| PARSE_INADDR | |
| PARSE_DEFAULT | |
| PARSE_IN_RANGE | |
| PARSE_OUT_RANGE | |
| PARSE_PORT_MASK | |
| PARSE_PORT_IGNORE | |
| PARSE_PORT_REQUIRE | |
| PARSE_PORT_FORBID |
Definition at line 472 of file config.h.
00472 { 00473 /* low 4 bits of flags are used for the operand type */ 00474 PARSE_TYPE = 0x000f, 00475 /* numeric types, with optional default value and bound checks. 00476 * Additional arguments are passed by value. 00477 */ 00478 PARSE_INT32 = 0x0001, 00479 PARSE_UINT32 = 0x0002, 00480 PARSE_DOUBLE = 0x0003, 00481 #if 0 /* not supported yet */ 00482 PARSE_INT16 = 0x0004, 00483 PARSE_UINT16 = 0x0005, 00484 #endif 00485 /* Returns a struct sockaddr_in, with optional default value 00486 * (passed by reference) and port handling (accept, ignore, 00487 * require, forbid). The format is 'host.name[:port]' 00488 */ 00489 PARSE_INADDR = 0x000f, 00490 00491 /* Other data types can be added as needed */ 00492 00493 /* If PARSE_DEFAULT is set, next argument is a default value 00494 * which is returned in case of error. The argument is passed 00495 * by value in case of numeric types, by reference in other cases. 00496 */ 00497 PARSE_DEFAULT = 0x0010, /* assign default on error */ 00498 00499 /* Request a range check, applicable to numbers. Two additional 00500 * arguments are passed by value, specifying the low-high end of 00501 * the range (inclusive). An error is returned if the value 00502 * is outside or inside the range, respectively. 00503 */ 00504 PARSE_IN_RANGE = 0x0020, /* accept values inside a range */ 00505 PARSE_OUT_RANGE = 0x0040, /* accept values outside a range */ 00506 00507 /* Port handling, for sockaddr_in. accept/ignore/require/forbid 00508 * port number after the hostname or address. 00509 */ 00510 PARSE_PORT_MASK = 0x0300, /* 0x000: accept port if present */ 00511 PARSE_PORT_IGNORE = 0x0100, /* 0x100: ignore port if present */ 00512 PARSE_PORT_REQUIRE = 0x0200, /* 0x200: require port number */ 00513 PARSE_PORT_FORBID = 0x0300, /* 0x100: forbid port number */ 00514 };
| 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 55 of file config.h.
00055 { 00056 RQ_INTEGER1, 00057 RQ_UINTEGER1, 00058 RQ_INTEGER2, 00059 RQ_UINTEGER2, 00060 RQ_INTEGER3, 00061 RQ_UINTEGER3, 00062 RQ_INTEGER4, 00063 RQ_UINTEGER4, 00064 RQ_INTEGER8, 00065 RQ_UINTEGER8, 00066 RQ_CHAR, 00067 RQ_FLOAT, 00068 RQ_DATE, 00069 RQ_DATETIME, 00070 } require_type;
| void ast_category_append | ( | struct ast_config * | config, | |
| struct ast_category * | cat | |||
| ) |
Definition at line 507 of file config.c.
References config, and ast_category::include_level.
Referenced by add_cfg_entry(), add_rt_multi_cfg_entry(), config_curl(), config_ldap(), config_odbc(), config_pgsql(), handle_updates(), process_text_line(), realtime_directory(), realtime_multi_curl(), realtime_multi_ldap(), realtime_multi_odbc(), and realtime_multi_pgsql().
00508 { 00509 if (config->last) 00510 config->last->next = category; 00511 else 00512 config->root = category; 00513 category->include_level = config->include_level; 00514 config->last = category; 00515 config->current = category; 00516 }
| 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 617 of file config.c.
References config, ast_category::name, ast_category::next, and next_available_category().
Referenced by __queues_show(), action_getconfig(), action_getconfigjson(), action_listcategories(), aji_load_config(), ast_cli_perms_init(), complete_sipnotify(), config_load(), get_insecure_variable_from_config(), gtalk_load_config(), iax_provision_reload(), jingle_load_config(), load_config(), load_indications(), load_module(), load_moh_classes(), load_odbc_config(), load_tech_calendars(), misdn_cfg_init(), osp_load(), parse_config(), pbx_load_config(), pbx_load_users(), read_agent_config(), realtime_directory(), realtime_switch_common(), reload(), reload_config(), reload_followme(), reload_queue_rules(), reload_queues(), rpt_master(), search_directory(), search_directory_sub(), set_config(), setup_dahdi(), show_users_realtime(), sla_load_config(), update_realtime_members(), and vm_change_password().
00618 { 00619 struct ast_category *cat = NULL; 00620 00621 if (prev && config->last_browse && (config->last_browse->name == prev)) 00622 cat = config->last_browse->next; 00623 else if (!prev && config->root) 00624 cat = config->root; 00625 else if (prev) { 00626 for (cat = config->root; cat; cat = cat->next) { 00627 if (cat->name == prev) { 00628 cat = cat->next; 00629 break; 00630 } 00631 } 00632 if (!cat) { 00633 for (cat = config->root; cat; cat = cat->next) { 00634 if (!strcasecmp(cat->name, prev)) { 00635 cat = cat->next; 00636 break; 00637 } 00638 } 00639 } 00640 } 00641 00642 if (cat) 00643 cat = next_available_category(cat); 00644 00645 config->last_browse = cat; 00646 return (cat) ? cat->name : NULL; 00647 }
| int ast_category_delete | ( | struct ast_config * | cfg, | |
| const char * | category | |||
| ) |
Definition at line 778 of file config.c.
References ast_category_destroy(), ast_config::last, ast_category::next, and ast_config::root.
Referenced by handle_updates().
00779 { 00780 struct ast_category *prev=NULL, *cat; 00781 00782 cat = cfg->root; 00783 while (cat) { 00784 if (cat->name == category) { 00785 if (prev) { 00786 prev->next = cat->next; 00787 if (cat == cfg->last) 00788 cfg->last = prev; 00789 } else { 00790 cfg->root = cat->next; 00791 if (cat == cfg->last) 00792 cfg->last = NULL; 00793 } 00794 ast_category_destroy(cat); 00795 return 0; 00796 } 00797 prev = cat; 00798 cat = cat->next; 00799 } 00800 00801 prev = NULL; 00802 cat = cfg->root; 00803 while (cat) { 00804 if (!strcasecmp(cat->name, category)) { 00805 if (prev) { 00806 prev->next = cat->next; 00807 if (cat == cfg->last) 00808 cfg->last = prev; 00809 } else { 00810 cfg->root = cat->next; 00811 if (cat == cfg->last) 00812 cfg->last = NULL; 00813 } 00814 ast_category_destroy(cat); 00815 return 0; 00816 } 00817 prev = cat; 00818 cat = cat->next; 00819 } 00820 return -1; 00821 }
| void ast_category_destroy | ( | struct ast_category * | cat | ) |
Definition at line 567 of file config.c.
References ast_destroy_comments(), ast_destroy_template_list(), ast_free, ast_variables_destroy(), ast_category::file, free, and ast_category::root.
Referenced by add_cfg_entry(), ast_category_delete(), ast_config_destroy(), process_text_line(), and realtime_multi_odbc().
00568 { 00569 ast_variables_destroy(cat->root); 00570 if (cat->file) { 00571 free(cat->file); 00572 cat->file = 0; 00573 } 00574 ast_destroy_comments(cat); 00575 ast_destroy_template_list(cat); 00576 ast_free(cat); 00577 }
| struct ast_variable* ast_category_detach_variables | ( | struct ast_category * | cat | ) |
Definition at line 649 of file config.c.
References ast_category::last, and ast_category::root.
Referenced by realtime_switch_common().
00650 { 00651 struct ast_variable *v; 00652 00653 v = cat->root; 00654 cat->root = NULL; 00655 cat->last = NULL; 00656 00657 return v; 00658 }
| 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 823 of file config.c.
References ast_variables_destroy(), ast_category::last, ast_category::name, ast_category::next, ast_config::root, and ast_category::root.
Referenced by handle_updates().
00824 { 00825 struct ast_category *cat; 00826 00827 for (cat = cfg->root; cat; cat = cat->next) { 00828 if (!strcasecmp(cat->name, category)) 00829 continue; 00830 ast_variables_destroy(cat->root); 00831 cat->root = NULL; 00832 cat->last = NULL; 00833 return 0; 00834 } 00835 00836 return -1; 00837 }
| 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 502 of file config.c.
References ast_category_get(), and config.
00503 { 00504 return !!ast_category_get(config, category_name); 00505 }
| struct ast_variable* ast_category_first | ( | struct ast_category * | cat | ) |
given a pointer to a category, return the root variable. This is equivalent to ast_variable_browse(), but more efficient if we already have the struct ast_category * (e.g. from ast_category_get())
return the first var of a category
Definition at line 603 of file config.c.
References ast_category::root.
Referenced by process_text_line().
| struct ast_category* ast_category_get | ( | const struct ast_config * | config, | |
| const char * | category_name | |||
| ) |
Retrieve a category if it exists.
| config | which config to use | |
| category_name | name of the category you're looking for This will search through the categories within a given config file for a match. |
| pointer | to category if found | |
| NULL | if not. |
Definition at line 497 of file config.c.
References category_get(), and config.
Referenced by ast_category_exist(), ast_category_root(), ast_variable_browse(), handle_updates(), realtime_directory(), realtime_switch_common(), vm_change_password(), and vm_forwardoptions().
00498 { 00499 return category_get(config, category_name, 0); 00500 }
| 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 518 of file config.c.
References config, ast_category::name, and ast_category::next.
Referenced by handle_updates().
00519 { 00520 struct ast_category *cur_category; 00521 00522 if (!cat || !match) 00523 return; 00524 if (!strcasecmp(config->root->name, match)) { 00525 cat->next = config->root; 00526 config->root = cat; 00527 return; 00528 } 00529 for (cur_category = config->root; cur_category; cur_category = cur_category->next) { 00530 if (!strcasecmp(cur_category->next->name, match)) { 00531 cat->next = cur_category->next; 00532 cur_category->next = cat; 00533 break; 00534 } 00535 } 00536 }
| struct ast_category* ast_category_new | ( | const char * | name, | |
| const char * | in_file, | |||
| int | lineno | |||
| ) |
Create a category structure.
Definition at line 468 of file config.c.
References ast_calloc, ast_copy_string(), and strdup.
Referenced by add_cfg_entry(), add_rt_multi_cfg_entry(), config_curl(), config_ldap(), config_odbc(), config_pgsql(), handle_updates(), process_text_line(), realtime_directory(), realtime_multi_curl(), realtime_multi_ldap(), realtime_multi_odbc(), and realtime_multi_pgsql().
00469 { 00470 struct ast_category *category; 00471 00472 if ((category = ast_calloc(1, sizeof(*category)))) 00473 ast_copy_string(category->name, name, sizeof(category->name)); 00474 category->file = strdup(in_file); 00475 category->lineno = lineno; /* if you don't know the lineno, set it to 999999 or something real big */ 00476 return category; 00477 }
| void ast_category_rename | ( | struct ast_category * | cat, | |
| const char * | name | |||
| ) |
Definition at line 660 of file config.c.
References ast_copy_string(), and ast_category::name.
Referenced by handle_updates(), realtime_multi_curl(), realtime_multi_odbc(), and realtime_multi_pgsql().
00661 { 00662 ast_copy_string(cat->name, name, sizeof(cat->name)); 00663 }
| struct ast_variable* ast_category_root | ( | struct ast_config * | config, | |
| char * | cat | |||
| ) |
returns the root ast_variable of a config
| config | pointer to an ast_config data structure | |
| cat | name of the category for which you want the root |
Definition at line 608 of file config.c.
References ast_category_get(), config, and ast_category::root.
Referenced by get_insecure_variable_from_config().
00609 { 00610 struct ast_category *category = ast_category_get(config, cat); 00611 00612 if (category) 00613 return category->root; 00614 return NULL; 00615 }
| 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 2156 of file config.c.
References ast_realtime_enabled(), and find_engine().
Referenced by __queues_show(), _sip_show_peer(), _sip_show_peers(), ast_queue_log(), copy_plain_file(), destroy_association(), handle_response_peerpoke(), handle_voicemail_show_users(), leave_voicemail(), load_module(), local_ast_moh_start(), realtime_peer(), realtime_update_peer(), rename_file(), sip_poke_noanswer(), sip_show_settings(), and vm_delete().
02157 { 02158 struct ast_config_engine *eng; 02159 if (!ast_realtime_enabled()) { 02160 return 0; /* There are no engines at all so fail early */ 02161 } 02162 02163 eng = find_engine(family, NULL, 0, NULL, 0); 02164 if (eng) 02165 return 1; 02166 return 0; 02167 }
| 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 839 of file config.c.
References ast_category_destroy(), ast_free, ast_includes_destroy(), ast_config::includes, ast_category::next, and ast_config::root.
Referenced by __ast_http_post_load(), __ast_udptl_reload(), __queues_show(), _dsp_init(), action_getconfig(), action_listcategories(), action_updateconfig(), advanced_options(), ast_config_load2(), conf_exec(), config_function_read(), config_load(), config_module(), directory_exec(), do_reload(), festival_exec(), find_conf(), handle_cli_dialplan_save(), iax_provision_reload(), init_logger_chain(), load_config(), load_config_meetme(), load_indications(), load_module(), load_realtime_queue(), load_rpt_vars(), make_email_file(), misdn_cfg_init(), node_lookup(), odbc_load_module(), osp_load(), parse_config(), pbx_load_users(), play_message(), prep_email_sub_vars(), private_enum_init(), read_agent_config(), read_config_maps(), realtime_directory(), realtime_multi_handler(), realtime_switch_common(), reload(), reload_config(), reload_followme(), reload_queue_rules(), reload_queues(), rpt_master(), rtp_reload(), run_startup_commands(), set_config(), setup_dahdi(), show_users_realtime(), sla_load_config(), store_config(), tds_load_module(), unload_module(), update_realtime_members(), and vm_forwardoptions().
00840 { 00841 struct ast_category *cat, *catn; 00842 00843 if (!cfg) 00844 return; 00845 00846 ast_includes_destroy(cfg->includes); 00847 00848 cat = cfg->root; 00849 while (cat) { 00850 catn = cat; 00851 cat = cat->next; 00852 ast_category_destroy(catn); 00853 } 00854 ast_free(cfg); 00855 }
| int ast_config_engine_deregister | ( | struct ast_config_engine * | del | ) |
Deregister config engine.
| 0 | Always |
Definition at line 1982 of file config.c.
References ast_mutex_lock(), ast_mutex_unlock(), config_engine_list, config_lock, last, and ast_config_engine::next.
Referenced by unload_module().
01983 { 01984 struct ast_config_engine *ptr, *last=NULL; 01985 01986 ast_mutex_lock(&config_lock); 01987 01988 for (ptr = config_engine_list; ptr; ptr=ptr->next) { 01989 if (ptr == del) { 01990 if (last) 01991 last->next = ptr->next; 01992 else 01993 config_engine_list = ptr->next; 01994 break; 01995 } 01996 last = ptr; 01997 } 01998 01999 ast_mutex_unlock(&config_lock); 02000 02001 return 0; 02002 }
| int ast_config_engine_register | ( | struct ast_config_engine * | newconfig | ) |
Register config engine.
| 1 | Always |
Definition at line 1963 of file config.c.
References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), config_engine_list, config_lock, LOG_NOTICE, ast_config_engine::name, and ast_config_engine::next.
Referenced by load_module().
01964 { 01965 struct ast_config_engine *ptr; 01966 01967 ast_mutex_lock(&config_lock); 01968 01969 if (!config_engine_list) { 01970 config_engine_list = new; 01971 } else { 01972 for (ptr = config_engine_list; ptr->next; ptr=ptr->next); 01973 ptr->next = new; 01974 } 01975 01976 ast_mutex_unlock(&config_lock); 01977 ast_log(LOG_NOTICE,"Registered Config Engine %s\n", new->name); 01978 01979 return 1; 01980 }
| struct ast_category* ast_config_get_current_category | ( | const struct ast_config * | cfg | ) |
Retrieve the current category name being built. API for backend configuration engines while building a configuration set.
Definition at line 857 of file config.c.
References ast_config::current.
Referenced by config_curl(), config_odbc(), and config_text_file_load().
00858 { 00859 return cfg->current; 00860 }
| struct ast_config* ast_config_internal_load | ( | const char * | configfile, | |
| struct ast_config * | cfg, | |||
| struct ast_flags | flags, | |||
| const char * | suggested_incl_file, | |||
| const char * | who_asked | |||
| ) |
Definition at line 2044 of file config.c.
References ast_log(), config_engine_list, 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, table, and text_file_engine.
Referenced by add_cfg_entry(), ast_config_load2(), config_curl(), config_ldap(), config_odbc(), config_pgsql(), process_text_line(), and read_config_maps().
02045 { 02046 char db[256]; 02047 char table[256]; 02048 struct ast_config_engine *loader = &text_file_engine; 02049 struct ast_config *result; 02050 02051 /* The config file itself bumps include_level by 1 */ 02052 if (cfg->max_include_level > 0 && cfg->include_level == cfg->max_include_level + 1) { 02053 ast_log(LOG_WARNING, "Maximum Include level (%d) exceeded\n", cfg->max_include_level); 02054 return NULL; 02055 } 02056 02057 cfg->include_level++; 02058 02059 if (strcmp(filename, extconfig_conf) && strcmp(filename, "asterisk.conf") && config_engine_list) { 02060 struct ast_config_engine *eng; 02061 02062 eng = find_engine(filename, db, sizeof(db), table, sizeof(table)); 02063 02064 02065 if (eng && eng->load_func) { 02066 loader = eng; 02067 } else { 02068 eng = find_engine("global", db, sizeof(db), table, sizeof(table)); 02069 if (eng && eng->load_func) 02070 loader = eng; 02071 } 02072 } 02073 02074 result = loader->load_func(db, table, filename, cfg, flags, suggested_include_file, who_asked); 02075 02076 if (result && result != CONFIG_STATUS_FILEINVALID && result != CONFIG_STATUS_FILEUNCHANGED) 02077 result->include_level--; 02078 else if (result != CONFIG_STATUS_FILEINVALID) 02079 cfg->include_level--; 02080 02081 return result; 02082 }
| struct ast_config* ast_config_load2 | ( | const char * | filename, | |
| const char * | who_asked, | |||
| struct ast_flags | flags | |||
| ) |
Load a config file.
| filename | path of file to open. If no preceding '/' character, path is considered relative to AST_CONFIG_DIR Create a config structure from a given configuration file. | |
| who_asked | The module which is making this request. | |
| flags | Optional flags: CONFIG_FLAG_WITHCOMMENTS - load the file with comments intact; CONFIG_FLAG_FILEUNCHANGED - check the file mtime and return CONFIG_STATUS_FILEUNCHANGED if the mtime is the same; or CONFIG_FLAG_NOCACHE - don't cache file mtime (main purpose of this option is to save memory on temporary files). |
| NULL | on error |
Definition at line 2084 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(), ast_xmldoc_load_documentation(), do_reload(), iax_provision_reload(), init_logger_chain(), load_config(), load_indications(), load_modules(), misdn_cfg_init(), private_enum_init(), rtp_reload(), and run_startup_commands().
02085 { 02086 struct ast_config *cfg; 02087 struct ast_config *result; 02088 02089 cfg = ast_config_new(); 02090 if (!cfg) 02091 return NULL; 02092 02093 result = ast_config_internal_load(filename, cfg, flags, "", who_asked); 02094 if (!result || result == CONFIG_STATUS_FILEUNCHANGED || result == CONFIG_STATUS_FILEINVALID) 02095 ast_config_destroy(cfg); 02096 02097 return result; 02098 }
| struct ast_config* ast_config_new | ( | void | ) |
Create a new base configuration structure.
Definition at line 677 of file config.c.
References ast_calloc, config, and MAX_INCLUDE_LEVEL.
Referenced by ast_config_load2(), read_config_maps(), realtime_multi_curl(), realtime_multi_handler(), realtime_multi_ldap(), realtime_multi_odbc(), and realtime_multi_pgsql().
00678 { 00679 struct ast_config *config; 00680 00681 if ((config = ast_calloc(1, sizeof(*config)))) 00682 config->max_include_level = MAX_INCLUDE_LEVEL; 00683 return config; 00684 }
| 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 409 of file config.c.
References ast_variable_retrieve().
Referenced by load_config(), pbx_load_users(), and search_directory_sub().
00410 { 00411 const char *tmp; 00412 tmp = ast_variable_retrieve(cfg, cat, var); 00413 if (!tmp) { 00414 tmp = ast_variable_retrieve(cfg, "general", var); 00415 } 00416 return tmp; 00417 }
| 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 862 of file config.c.
References ast_config::current.
00863 { 00864 /* cast below is just to silence compiler warning about dropping "const" */ 00865 cfg->current = (struct ast_category *) cat; 00866 }
| int ast_config_text_file_save | ( | const char * | filename, | |
| const struct ast_config * | cfg, | |||
| const char * | generator | |||
| ) |
Definition at line 1604 of file config.c.
References ao2_container_alloc, ao2_ref, ast_debug, AST_LIST_EMPTY, AST_LIST_LAST, AST_LIST_TRAVERSE, ast_verb, ast_comment::cmt, errno, ast_config_include::exec, ast_config_include::exec_file, f, ast_category::file, gen_header(), hash_string(), hashtab_compare_strings(), ast_category::ignored, ast_config_include::include_location_file, ast_config_include::include_location_lineno, ast_config_include::included_file, ast_config::includes, insert_leading_blank_lines(), ast_category_template_instance::inst, ast_category::lineno, ast_category::name, ast_category_template_instance::name, ast_variable::name, ast_config_include::next, ast_comment::next, ast_category_template_instance::next, ast_variable::next, ast_category::next, option_debug, ast_config_include::output, ast_category::precomments, ast_config::root, ast_category::root, ast_category::sameline, set_fn(), ast_category::template_instances, ast_category::trailing, ast_variable::value, and var.
Referenced by action_updateconfig(), config_text_file_save(), vm_change_password(), and vm_forwardoptions().
01605 { 01606 FILE *f; 01607 char fn[256]; 01608 struct ast_variable *var; 01609 struct ast_category *cat; 01610 struct ast_comment *cmt; 01611 struct ast_config_include *incl; 01612 int blanklines = 0; 01613 struct ao2_container *fileset = ao2_container_alloc(180000, hash_string, hashtab_compare_strings); 01614 struct inclfile *fi = 0; 01615 01616 /* reset all the output flags, in case this isn't our first time saving this data */ 01617 01618 for (incl=cfg->includes; incl; incl = incl->next) 01619 incl->output = 0; 01620 01621 /* go thru all the inclusions and make sure all the files involved (configfile plus all its inclusions) 01622 are all truncated to zero bytes and have that nice header*/ 01623 01624 for (incl=cfg->includes; incl; incl = incl->next) 01625 { 01626 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*/ 01627 FILE *f1; 01628 01629 set_fn(fn, sizeof(fn), incl->included_file, configfile, fileset, &fi); /* normally, fn is just set to incl->included_file, prepended with config dir if relative */ 01630 f1 = fopen(fn,"w"); 01631 if (f1) { 01632 gen_header(f1, configfile, fn, generator); 01633 fclose(f1); /* this should zero out the file */ 01634 } else { 01635 ast_debug(1, "Unable to open for writing: %s\n", fn); 01636 ast_verb(2, "Unable to write %s (%s)", fn, strerror(errno)); 01637 } 01638 ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */ 01639 fi = 0; 01640 } 01641 } 01642 01643 set_fn(fn, sizeof(fn), 0, configfile, fileset, &fi); /* just set fn to absolute ver of configfile */ 01644 #ifdef __CYGWIN__ 01645 if ((f = fopen(fn, "w+"))) { 01646 #else 01647 if ((f = fopen(fn, "w"))) { 01648 #endif 01649 ast_verb(2, "Saving '%s': ", fn); 01650 gen_header(f, configfile, fn, generator); 01651 cat = cfg->root; 01652 fclose(f); 01653 ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */ 01654 01655 /* from here out, we open each involved file and concat the stuff we need to add to the end and immediately close... */ 01656 /* since each var, cat, and associated comments can come from any file, we have to be 01657 mobile, and open each file, print, and close it on an entry-by-entry basis */ 01658 01659 while (cat) { 01660 set_fn(fn, sizeof(fn), cat->file, configfile, fileset, &fi); 01661 f = fopen(fn, "a"); 01662 if (!f) 01663 { 01664 ast_debug(1, "Unable to open for writing: %s\n", fn); 01665 ast_verb(2, "Unable to write %s (%s)", fn, strerror(errno)); 01666 ao2_ref(fileset, -1); 01667 return -1; 01668 } 01669 01670 /* dump any includes that happen before this category header */ 01671 for (incl=cfg->includes; incl; incl = incl->next) { 01672 if (strcmp(incl->include_location_file, cat->file) == 0){ 01673 if (cat->lineno > incl->include_location_lineno && !incl->output) { 01674 if (incl->exec) 01675 fprintf(f,"#exec \"%s\"\n", incl->exec_file); 01676 else 01677 fprintf(f,"#include \"%s\"\n", incl->included_file); 01678 incl->output = 1; 01679 } 01680 } 01681 } 01682 01683 insert_leading_blank_lines(f, fi, cat->precomments, cat->lineno); 01684 /* Dump section with any appropriate comment */ 01685 for (cmt = cat->precomments; cmt; cmt=cmt->next) { 01686 char *cmtp = cmt->cmt; 01687 while (*cmtp == ';' && *(cmtp+1) == '!') { 01688 char *cmtp2 = strchr(cmtp+1, '\n'); 01689 if (cmtp2) 01690 cmtp = cmtp2+1; 01691 else cmtp = 0; 01692 } 01693 if (cmtp) 01694 fprintf(f,"%s", cmtp); 01695 } 01696 fprintf(f, "[%s]", cat->name); 01697 if (cat->ignored || !AST_LIST_EMPTY(&cat->template_instances)) { 01698 fprintf(f, "("); 01699 if (cat->ignored) { 01700 fprintf(f, "!"); 01701 } 01702 if (cat->ignored && !AST_LIST_EMPTY(&cat->template_instances)) { 01703 fprintf(f, ","); 01704 } 01705 if (!AST_LIST_EMPTY(&cat->template_instances)) { 01706 struct ast_category_template_instance *x; 01707 AST_LIST_TRAVERSE(&cat->template_instances, x, next) { 01708 fprintf(f,"%s",x->name); 01709 if (x != AST_LIST_LAST(&cat->template_instances)) 01710 fprintf(f,","); 01711 } 01712 } 01713 fprintf(f, ")"); 01714 } 01715 for(cmt = cat->sameline; cmt; cmt=cmt->next) 01716 { 01717 fprintf(f,"%s", cmt->cmt); 01718 } 01719 if (!cat->sameline) 01720 fprintf(f,"\n"); 01721 for (cmt = cat->trailing; cmt; cmt=cmt->next) { 01722 if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!') 01723 fprintf(f,"%s", cmt->cmt); 01724 } 01725 fclose(f); 01726 ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */ 01727 fi = 0; 01728 01729 var = cat->root; 01730 while (var) { 01731 struct ast_category_template_instance *x; 01732 int found = 0; 01733 AST_LIST_TRAVERSE(&cat->template_instances, x, next) { 01734 struct ast_variable *v; 01735 for (v = x->inst->root; v; v = v->next) { 01736 if (!strcasecmp(var->name, v->name) && !strcmp(var->value, v->value)) { 01737 found = 1; 01738 break; 01739 } 01740 } 01741 if (found) 01742 break; 01743 } 01744 if (found) { 01745 var = var->next; 01746 continue; 01747 } 01748 set_fn(fn, sizeof(fn), var->file, configfile, fileset, &fi); 01749 f = fopen(fn, "a"); 01750 if (!f) 01751 { 01752 ast_debug(1, "Unable to open for writing: %s\n", fn); 01753 ast_verb(2, "Unable to write %s (%s)", fn, strerror(errno)); 01754 ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */ 01755 fi = 0; 01756 ao2_ref(fileset, -1); 01757 return -1; 01758 } 01759 01760 /* dump any includes that happen before this category header */ 01761 for (incl=cfg->includes; incl; incl = incl->next) { 01762 if (strcmp(incl->include_location_file, var->file) == 0){ 01763 if (var->lineno > incl->include_location_lineno && !incl->output) { 01764 if (incl->exec) 01765 fprintf(f,"#exec \"%s\"\n", incl->exec_file); 01766 else 01767 fprintf(f,"#include \"%s\"\n", incl->included_file); 01768 incl->output = 1; 01769 } 01770 } 01771 } 01772 01773 insert_leading_blank_lines(f, fi, var->precomments, var->lineno); 01774 for (cmt = var->precomments; cmt; cmt=cmt->next) { 01775 if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!') 01776 fprintf(f,"%s", cmt->cmt); 01777 } 01778 if (var->sameline) 01779 fprintf(f, "%s %s %s %s", var->name, (var->object ? "=>" : "="), var->value, var->sameline->cmt); 01780 else 01781 fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="), var->value); 01782 for (cmt = var->trailing; cmt; cmt=cmt->next) { 01783 if (cmt->cmt[0] != ';' || cmt->cmt[1] != '!') 01784 fprintf(f,"%s", cmt->cmt); 01785 } 01786 if (var->blanklines) { 01787 blanklines = var->blanklines; 01788 while (blanklines--) 01789 fprintf(f, "\n"); 01790 } 01791 01792 fclose(f); 01793 ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */ 01794 fi = 0; 01795 01796 var = var->next; 01797 } 01798 cat = cat->next; 01799 } 01800 if (!option_debug) 01801 ast_verb(2, "Saved\n"); 01802 } else { 01803 ast_debug(1, "Unable to open for writing: %s\n", fn); 01804 ast_verb(2, "Unable to write (%s)", strerror(errno)); 01805 ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */ 01806 ao2_ref(fileset, -1); 01807 return -1; 01808 } 01809 01810 /* Now, for files with trailing #include/#exec statements, 01811 we have to make sure every entry is output */ 01812 01813 for (incl=cfg->includes; incl; incl = incl->next) { 01814 if (!incl->output) { 01815 /* open the respective file */ 01816 set_fn(fn, sizeof(fn), incl->include_location_file, configfile, fileset, &fi); 01817 f = fopen(fn, "a"); 01818 if (!f) 01819 { 01820 ast_debug(1, "Unable to open for writing: %s\n", fn); 01821 ast_verb(2, "Unable to write %s (%s)", fn, strerror(errno)); 01822 ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */ 01823 fi = 0; 01824 ao2_ref(fileset, -1); 01825 return -1; 01826 } 01827 01828 /* output the respective include */ 01829 if (incl->exec) 01830 fprintf(f,"#exec \"%s\"\n", incl->exec_file); 01831 else 01832 fprintf(f,"#include \"%s\"\n", incl->included_file); 01833 fclose(f); 01834 incl->output = 1; 01835 ao2_ref(fi,-1); /* we are giving up this reference to the object ptd to by fi */ 01836 fi = 0; 01837 } 01838 } 01839 ao2_ref(fileset, -1); /* this should destroy the hash container */ 01840 01841 return 0; 01842 }
| 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 2275 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().
02276 { 02277 struct ast_config_engine *eng; 02278 int res = -1; 02279 char db[256]; 02280 char table[256]; 02281 va_list ap; 02282 02283 va_start(ap, lookup); 02284 eng = find_engine(family, db, sizeof(db), table, sizeof(table)); 02285 if (eng && eng->destroy_func) 02286 res = eng->destroy_func(db, table, keyfield, lookup, ap); 02287 va_end(ap); 02288 02289 return res; 02290 }
| struct ast_config_include* ast_include_find | ( | struct ast_config * | conf, | |
| const char * | included_file | |||
| ) |
Definition at line 337 of file config.c.
References ast_config_include::included_file, ast_config::includes, and ast_config_include::next.
Referenced by ast_include_new().
00338 { 00339 struct ast_config_include *x; 00340 for (x=conf->includes;x;x=x->next) { 00341 if (strcmp(x->included_file,included_file) == 0) 00342 return x; 00343 } 00344 return 0; 00345 }
| struct ast_config_include* ast_include_new | ( | struct ast_config * | conf, | |
| const char * | from_file, | |||
| const char * | included_file, | |||
| int | is_exec, | |||
| const char * | exec_file, | |||
| int | from_lineno, | |||
| char * | real_included_file_name, | |||
| int | real_included_file_name_size | |||
| ) |
Definition at line 246 of file config.c.
References ast_calloc, ast_include_find(), ast_log(), ast_strdup, ast_strlen_zero(), ast_config::includes, and LOG_WARNING.
Referenced by process_text_line().
00247 { 00248 /* a file should be included ONCE. Otherwise, if one of the instances is changed, 00249 * then all be changed. -- how do we know to include it? -- Handling modified 00250 * instances is possible, I'd have 00251 * to create a new master for each instance. */ 00252 struct ast_config_include *inc; 00253 struct stat statbuf; 00254 00255 inc = ast_include_find(conf, included_file); 00256 if (inc) { 00257 do { 00258 inc->inclusion_count++; 00259 snprintf(real_included_file_name, real_included_file_name_size, "%s~~%d", included_file, inc->inclusion_count); 00260 } while (stat(real_included_file_name, &statbuf) == 0); 00261 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); 00262 } else 00263 *real_included_file_name = 0; 00264 00265 inc = ast_calloc(1,sizeof(struct ast_config_include)); 00266 inc->include_location_file = ast_strdup(from_file); 00267 inc->include_location_lineno = from_lineno; 00268 if (!ast_strlen_zero(real_included_file_name)) 00269 inc->included_file = ast_strdup(real_included_file_name); 00270 else 00271 inc->included_file = ast_strdup(included_file); 00272 00273 inc->exec = is_exec; 00274 if (is_exec) 00275 inc->exec_file = ast_strdup(exec_file); 00276 00277 /* attach this new struct to the conf struct */ 00278 inc->next = conf->includes; 00279 conf->includes = inc; 00280 00281 return inc; 00282 }
| void ast_include_rename | ( | struct ast_config * | conf, | |
| const char * | from_file, | |||
| const char * | to_file | |||
| ) |
Definition at line 284 of file config.c.
References ast_category::file, ast_variable::file, free, ast_config_include::include_location_file, ast_config::includes, ast_config_include::next, ast_category::next, ast_variable::next, ast_config::root, ast_category::root, and strdup.
Referenced by action_updateconfig().
00285 { 00286 struct ast_config_include *incl; 00287 struct ast_category *cat; 00288 struct ast_variable *v; 00289 00290 int from_len = strlen(from_file); 00291 int to_len = strlen(to_file); 00292 00293 if (strcmp(from_file, to_file) == 0) /* no use wasting time if the name is the same */ 00294 return; 00295 00296 /* the manager code allows you to read in one config file, then 00297 * write it back out under a different name. But, the new arrangement 00298 * ties output lines to the file name. So, before you try to write 00299 * the config file to disk, better riffle thru the data and make sure 00300 * the file names are changed. 00301 */ 00302 /* file names are on categories, includes (of course), and on variables. So, 00303 * traverse all this and swap names */ 00304 00305 for (incl = conf->includes; incl; incl=incl->next) { 00306 if (strcmp(incl->include_location_file,from_file) == 0) { 00307 if (from_len >= to_len) 00308 strcpy(incl->include_location_file, to_file); 00309 else { 00310 free(incl->include_location_file); 00311 incl->include_location_file = strdup(to_file); 00312 } 00313 } 00314 } 00315 for (cat = conf->root; cat; cat = cat->next) { 00316 if (strcmp(cat->file,from_file) == 0) { 00317 if (from_len >= to_len) 00318 strcpy(cat->file, to_file); 00319 else { 00320 free(cat->file); 00321 cat->file = strdup(to_file); 00322 } 00323 } 00324 for (v = cat->root; v; v = v->next) { 00325 if (strcmp(v->file,from_file) == 0) { 00326 if (from_len >= to_len) 00327 strcpy(v->file, to_file); 00328 else { 00329 free(v->file); 00330 v->file = strdup(to_file); 00331 } 00332 } 00333 } 00334 } 00335 }
| struct ast_variable* ast_load_realtime | ( | const char * | family, | |
| ... | ||||
| ) |
Retrieve realtime configuration.
| family | which family/config to lookup This will use builtin configuration backends to look up a particular entity in realtime and return a variable list of its parameters. Note that unlike the variables in ast_config, the resulting list of variables MUST be freed with ast_variables_destroy() as there is no container. |
Note that you should use the constant SENTINEL to terminate arguments, in order to preserve cross-platform compatibility.
Definition at line 2126 of file config.c.
References ast_free, ast_load_realtime_helper(), ast_strlen_zero(), ast_variable::next, and ast_variable::value.
Referenced by conf_run(), copy_plain_file(), find_conf_realtime(), find_realtime(), find_user_realtime(), leave_queue(), load_realtime_queue(), local_ast_moh_start(), queue_function_queuewaitingcount(), realtime_alias(), realtime_peer(), realtime_switch_common(), realtime_user(), and rt_extend_conf().
02127 { 02128 struct ast_variable *res, *cur, *prev = NULL, *freeme = NULL; 02129 va_list ap; 02130 02131 va_start(ap, family); 02132 res = ast_load_realtime_helper(family, ap); 02133 va_end(ap); 02134 02135 /* Eliminate blank entries */ 02136 for (cur = res; cur; cur = cur->next) { 02137 if (freeme) { 02138 ast_free(freeme); 02139 freeme = NULL; 02140 } 02141 02142 if (ast_strlen_zero(cur->value)) { 02143 if (prev) 02144 prev->next = cur->next; 02145 else 02146 res = cur->next; 02147 freeme = cur; 02148 } else { 02149 prev = cur; 02150 } 02151 } 02152 return res; 02153 }
| struct ast_variable* ast_load_realtime_all | ( | const char * | family, | |
| ... | ||||
| ) |
Definition at line 2114 of file config.c.
References ast_load_realtime_helper().
Referenced by cli_realtime_load(), function_realtime_read(), function_realtime_readdestroy(), and realtimefield_read().
02115 { 02116 struct ast_variable *res; 02117 va_list ap; 02118 02119 va_start(ap, family); 02120 res = ast_load_realtime_helper(family, ap); 02121 va_end(ap); 02122 02123 return res; 02124 }
| struct ast_config* ast_load_realtime_multientry | ( | const char * | family, | |
| ... | ||||
| ) |
Retrieve realtime configuration.
| family | which family/config to lookup |
Note that you should use the constant SENTINEL to terminate arguments, in order to preserve cross-platform compatibility.
Definition at line 2207 of file config.c.
References db, find_engine(), ast_config_engine::realtime_multi_func, and table.
Referenced by __queues_show(), load_realtime_queue(), realtime_directory(), realtime_switch_common(), show_users_realtime(), and update_realtime_members().
02208 { 02209 struct ast_config_engine *eng; 02210 char db[256]; 02211 char table[256]; 02212 struct ast_config *res = NULL; 02213 va_list ap; 02214 02215 va_start(ap, family); 02216 eng = find_engine(family, db, sizeof(db), table, sizeof(table)); 02217 if (eng && eng->realtime_multi_func) 02218 res = eng->realtime_multi_func(db, table, ap); 02219 va_end(ap); 02220 02221 return res; 02222 }
| int ast_parse_arg | ( | const char * | arg, | |
| enum ast_parse_flags | flags, | |||
| void * | result, | |||
| ... | ||||
| ) |
The argument parsing routine.
| arg | the string to parse. It is not modified. | |
| flags | combination of ast_parse_flags to specify the return type and additional checks. | |
| result | pointer to the result. NULL is valid here, and can be used to perform only the validity checks. | |
| ... | extra arguments are required according to flags. |
| 0 | in case of success, != 0 otherwise. | |
| result | returns the parsed value in case of success, the default value in case of error, or it is left unchanged in case of error and no default specified. Note that in certain cases (e.g. sockaddr_in, with multi-field return values) some of the fields in result may be changed even if an error occurs. |
Definition at line 2295 of file config.c.
References ahp, ast_debug, ast_gethostbyname(), ast_inet_ntoa(), ast_strdupa, buf, hp, PARSE_DEFAULT, PARSE_DOUBLE, PARSE_IN_RANGE, PARSE_INADDR, PARSE_INT32, PARSE_OUT_RANGE, PARSE_PORT_FORBID, PARSE_PORT_IGNORE, PARSE_PORT_MASK, PARSE_PORT_REQUIRE, PARSE_TYPE, PARSE_UINT32, and strsep().
Referenced by ast_sip_ouraddrfor(), ast_tls_read_conf(), check_via_response(), and multicast_rtp_request().
02297 { 02298 va_list ap; 02299 int error = 0; 02300 02301 va_start(ap, p_result); 02302 switch (flags & PARSE_TYPE) { 02303 case PARSE_INT32: 02304 { 02305 int32_t *result = p_result; 02306 int32_t x, def = result ? *result : 0, 02307 high = (int32_t)0x7fffffff, 02308 low = (int32_t)0x80000000; 02309 /* optional argument: first default value, then range */ 02310 if (flags & PARSE_DEFAULT) 02311 def = va_arg(ap, int32_t); 02312 if (flags & (PARSE_IN_RANGE|PARSE_OUT_RANGE)) { 02313 /* range requested, update bounds */ 02314 low = va_arg(ap, int32_t); 02315 high = va_arg(ap, int32_t); 02316 } 02317 x = strtol(arg, NULL, 0); 02318 error = (x < low) || (x > high); 02319 if (flags & PARSE_OUT_RANGE) 02320 error = !error; 02321 if (result) 02322 *result = error ? def : x; 02323 ast_debug(3, 02324 "extract int from [%s] in [%d, %d] gives [%d](%d)\n", 02325 arg, low, high, 02326 result ? *result : x, error); 02327 break; 02328 } 02329 02330 case PARSE_UINT32: 02331 { 02332 uint32_t *result = p_result; 02333 uint32_t x, def = result ? *result : 0, 02334 low = 0, high = (uint32_t)~0; 02335 /* optional argument: first default value, then range */ 02336 if (flags & PARSE_DEFAULT) 02337 def = va_arg(ap, uint32_t); 02338 if (flags & (PARSE_IN_RANGE|PARSE_OUT_RANGE)) { 02339 /* range requested, update bounds */ 02340 low = va_arg(ap, uint32_t); 02341 high = va_arg(ap, uint32_t); 02342 } 02343 x = strtoul(arg, NULL, 0); 02344 error = (x < low) || (x > high); 02345 if (flags & PARSE_OUT_RANGE) 02346 error = !error; 02347 if (result) 02348 *result = error ? def : x; 02349 ast_debug(3, 02350 "extract uint from [%s] in [%u, %u] gives [%u](%d)\n", 02351 arg, low, high, 02352 result ? *result : x, error); 02353 break; 02354 } 02355 02356 case PARSE_DOUBLE: 02357 { 02358 double *result = p_result; 02359 double x, def = result ? *result : 0, 02360 low = -HUGE_VAL, high = HUGE_VAL; 02361 02362 /* optional argument: first default value, then range */ 02363 if (flags & PARSE_DEFAULT) 02364 def = va_arg(ap, double); 02365 if (flags & (PARSE_IN_RANGE|PARSE_OUT_RANGE)) { 02366 /* range requested, update bounds */ 02367 low = va_arg(ap, double); 02368 high = va_arg(ap, double); 02369 } 02370 x = strtod(arg, NULL); 02371 error = (x < low) || (x > high); 02372 if (flags & PARSE_OUT_RANGE) 02373 error = !error; 02374 if (result) 02375 *result = error ? def : x; 02376 ast_debug(3, 02377 "extract double from [%s] in [%f, %f] gives [%f](%d)\n", 02378 arg, low, high, 02379 result ? *result : x, error); 02380 break; 02381 } 02382 case PARSE_INADDR: 02383 { 02384 char *port, *buf; 02385 struct sockaddr_in _sa_buf; /* buffer for the result */ 02386 struct sockaddr_in *sa = p_result ? 02387 (struct sockaddr_in *)p_result : &_sa_buf; 02388 /* default is either the supplied value or the result itself */ 02389 struct sockaddr_in *def = (flags & PARSE_DEFAULT) ? 02390 va_arg(ap, struct sockaddr_in *) : sa; 02391 struct hostent *hp; 02392 struct ast_hostent ahp; 02393 02394 memset(&_sa_buf, '\0', sizeof(_sa_buf)); /* clear buffer */ 02395 /* duplicate the string to strip away the :port */ 02396 port = ast_strdupa(arg); 02397 buf = strsep(&port, ":"); 02398 sa->sin_family = AF_INET; /* assign family */ 02399 /* 02400 * honor the ports flag setting, assign default value 02401 * in case of errors or field unset. 02402 */ 02403 flags &= PARSE_PORT_MASK; /* the only flags left to process */ 02404 if (port) { 02405 if (flags == PARSE_PORT_FORBID) { 02406 error = 1; /* port was forbidden */ 02407 sa->sin_port = def->sin_port; 02408 } else if (flags == PARSE_PORT_IGNORE) 02409 sa->sin_port = def->sin_port; 02410 else /* accept or require */ 02411 sa->sin_port = htons(strtol(port, NULL, 0)); 02412 } else { 02413 sa->sin_port = def->sin_port; 02414 if (flags == PARSE_PORT_REQUIRE) 02415 error = 1; 02416 } 02417 /* Now deal with host part, even if we have errors before. */ 02418 hp = ast_gethostbyname(buf, &ahp); 02419 if (hp) /* resolved successfully */ 02420 memcpy(&sa->sin_addr, hp->h_addr, sizeof(sa->sin_addr)); 02421 else { 02422 error = 1; 02423 sa->sin_addr = def->sin_addr; 02424 } 02425 ast_debug(3, 02426 "extract inaddr from [%s] gives [%s:%d](%d)\n", 02427 arg, ast_inet_ntoa(sa->sin_addr), 02428 ntohs(sa->sin_port), error); 02429 break; 02430 } 02431 } 02432 va_end(ap); 02433 return error; 02434 }
| int ast_realtime_enabled | ( | void | ) |
Check if there's any realtime engines loaded.
Definition at line 2170 of file config.c.
References config_maps.
Referenced by action_coresettings(), ast_check_realtime(), and handle_show_settings().
02171 { 02172 return config_maps ? 1 : 0; 02173 }
| int ast_realtime_require_field | ( | const char * | family, | |
| ... | ||||
| ) |
Inform realtime what fields that may be stored.
| family | which family/config is referenced This will inform builtin configuration backends that particular fields may be updated during the use of that configuration section. This is mainly to be used during startup routines, to ensure that various fields exist in the backend. The backends may take various actions, such as creating new fields in the data store or warning the administrator that new fields may need to be created, in order to ensure proper function. |
A family should always specify its fields to the minimum necessary requirements to fulfill all possible values (within reason; for example, a timeout value may reasonably be specified as an INTEGER2, with size 5. Even though values above 32767 seconds are possible, they are unlikely to be useful, and we should not complain about that size).
| 0 | Required fields met specified standards | |
| -1 | One or more fields was missing or insufficient |
Definition at line 2175 of file config.c.
References db, find_engine(), ast_config_engine::require_func, and table.
Referenced by change_password_realtime(), conf_run(), and load_module().
02176 { 02177 struct ast_config_engine *eng; 02178 char db[256]; 02179 char table[256]; 02180 va_list ap; 02181 int res = -1; 02182 02183 va_start(ap, family); 02184 eng = find_engine(family, db, sizeof(db), table, sizeof(table)); 02185 if (eng && eng->require_func) { 02186 res = eng->require_func(db, table, ap); 02187 } 02188 va_end(ap); 02189 02190 return res; 02191 }
| int ast_rq_is_int | ( | require_type | type | ) | [inline] |
Check if require type is an integer type.
Definition at line 607 of file config.h.
Referenced by realtime_require_handler(), require_odbc(), and require_pgsql().
| int ast_store_realtime | ( | const char * | family, | |
| ... | ||||
| ) |
Create realtime configuration.
| family | which family/config to be created This function is used to create a parameter in realtime configuration space. |
Definition at line 2258 of file config.c.
References db, find_engine(), ast_config_engine::store_func, and table.
Referenced by ast_queue_log(), cli_realtime_store(), function_realtime_store(), and leave_voicemail().
02259 { 02260 struct ast_config_engine *eng; 02261 int res = -1; 02262 char db[256]; 02263 char table[256]; 02264 va_list ap; 02265 02266 va_start(ap, family); 02267 eng = find_engine(family, db, sizeof(db), table, sizeof(table)); 02268 if (eng && eng->store_func) 02269 res = eng->store_func(db, table, ap); 02270 va_end(ap); 02271 02272 return res; 02273 }
| 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 2193 of file config.c.
References db, find_engine(), table, and ast_config_engine::unload_func.
Referenced by __unload_module(), load_config(), reload(), reload_config(), and unload_module().
02194 { 02195 struct ast_config_engine *eng; 02196 char db[256]; 02197 char table[256]; 02198 int res = -1; 02199 02200 eng = find_engine(family, db, sizeof(db), table, sizeof(table)); 02201 if (eng && eng->unload_func) { 02202 res = eng->unload_func(db, table); 02203 } 02204 return res; 02205 }
| 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 2241 of file config.c.
References db, find_engine(), table, and ast_config_engine::update2_func.
Referenced by change_password_realtime(), and cli_realtime_update2().
02242 { 02243 struct ast_config_engine *eng; 02244 int res = -1; 02245 char db[256]; 02246 char table[256]; 02247 va_list ap; 02248 02249 va_start(ap, family); 02250 eng = find_engine(family, db, sizeof(db), table, sizeof(table)); 02251 if (eng && eng->update2_func) 02252 res = eng->update2_func(db, table, ap); 02253 va_end(ap); 02254 02255 return res; 02256 }
| 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 2224 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().
02225 { 02226 struct ast_config_engine *eng; 02227 int res = -1; 02228 char db[256]; 02229 char table[256]; 02230 va_list ap; 02231 02232 va_start(ap, lookup); 02233 eng = find_engine(family, db, sizeof(db), table, sizeof(table)); 02234 if (eng && eng->update_func) 02235 res = eng->update_func(db, table, keyfield, lookup, ap); 02236 va_end(ap); 02237 02238 return res; 02239 }
| void ast_variable_append | ( | struct ast_category * | category, | |
| struct ast_variable * | variable | |||
| ) |
Definition at line 348 of file config.c.
References ast_category::last, ast_variable::next, and ast_category::root.
Referenced by add_cfg_entry(), add_rt_multi_cfg_entry(), config_curl(), config_ldap(), config_odbc(), config_pgsql(), handle_updates(), inherit_category(), move_variables(), process_text_line(), realtime_directory(), realtime_multi_curl(), realtime_multi_ldap(), realtime_multi_odbc(), realtime_multi_pgsql(), and vm_change_password().
00349 { 00350 if (!variable) 00351 return; 00352 if (category->last) 00353 category->last->next = variable; 00354 else 00355 category->root = variable; 00356 category->last = variable; 00357 while (category->last->next) 00358 category->last = category->last->next; 00359 }
| struct ast_variable* ast_variable_browse | ( | const struct ast_config * | config, | |
| const char * | category | |||
| ) |
Goes through variables Somewhat similar in intent as the ast_category_browse. List variables of config file category.
| ast_variable | list on success | |
| NULL | on failure |
Definition at line 396 of file config.c.
References ast_category_get(), config, and ast_category::root.
Referenced by __ast_http_load(), __ast_http_post_load(), __init_manager(), action_getconfig(), action_getconfigjson(), adsi_load(), aji_load_config(), ast_cli_perms_init(), ast_readconfig(), ast_variable_retrieve(), ast_xmldoc_load_documentation(), build_calendar(), build_device(), build_event_channel(), caldav_load_calendar(), check_tx_freq(), collect_function_digits(), conf_exec(), config_load(), config_module(), do_say(), do_scheduler(), 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_rpt_vars(), misdn_cfg_init(), node_lookup(), odbc_load_module(), osp_create_provider(), parse_config(), parse_tone_zone(), pbx_load_config(), read_agent_config(), read_config_maps(), reload(), reload_config(), reload_followme(), reload_queue_rules(), reload_single_queue(), run_startup_commands(), search_directory_sub(), set_config(), setup_dahdi(), show_users_realtime(), sip_cli_notify(), sla_build_station(), sla_build_trunk(), smdi_load(), store_config(), and tds_load_module().
00397 { 00398 struct ast_category *cat = NULL; 00399 00400 if (category && config->last_browse && (config->last_browse->name == category)) { 00401 cat = config->last_browse; 00402 } else { 00403 cat = ast_category_get(config, category); 00404 } 00405 00406 return (cat) ? cat->root : NULL; 00407 }
| int ast_variable_delete | ( | struct ast_category * | category, | |
| const char * | variable, | |||
| const char * | match, | |||
| const char * | line | |||
| ) |
Definition at line 686 of file config.c.
References ast_strlen_zero(), ast_variables_destroy(), ast_category::last, ast_variable::name, ast_variable::next, ast_category::root, and ast_variable::value.
Referenced by handle_updates().
00687 { 00688 struct ast_variable *cur, *prev=NULL, *curn; 00689 int res = -1; 00690 int lineno = 0; 00691 00692 cur = category->root; 00693 while (cur) { 00694 if (cur->name == variable) { 00695 if (prev) { 00696 prev->next = cur->next; 00697 if (cur == category->last) 00698 category->last = prev; 00699 } else { 00700 category->root = cur->next; 00701 if (cur == category->last) 00702 category->last = NULL; 00703 } 00704 cur->next = NULL; 00705 ast_variables_destroy(cur); 00706 return 0; 00707 } 00708 prev = cur; 00709 cur = cur->next; 00710 } 00711 00712 prev = NULL; 00713 cur = category->root; 00714 while (cur) { 00715 curn = cur->next; 00716 if ((!ast_strlen_zero(line) && lineno == atoi(line)) || (ast_strlen_zero(line) && !strcasecmp(cur->name, variable) && (ast_strlen_zero(match) || !strcasecmp(cur->value, match)))) { 00717 if (prev) { 00718 prev->next = cur->next; 00719 if (cur == category->last) 00720 category->last = prev; 00721 } else { 00722 category->root = cur->next; 00723 if (cur == category->last) 00724 category->last = NULL; 00725 } 00726 cur->next = NULL; 00727 ast_variables_destroy(cur); 00728 res = 0; 00729 } else 00730 prev = cur; 00731 00732 cur = curn; 00733 lineno++; 00734 } 00735 return res; 00736 }
| void ast_variable_insert | ( | struct ast_category * | category, | |
| struct ast_variable * | variable, | |||
| const char * | line | |||
| ) |
Definition at line 361 of file config.c.
References ast_variable::next, and ast_category::root.
Referenced by handle_updates().
00362 { 00363 struct ast_variable *cur = category->root; 00364 int lineno; 00365 int insertline; 00366 00367 if (!variable || sscanf(line, "%d", &insertline) != 1) { 00368 return; 00369 } 00370 if (!insertline) { 00371 variable->next = category->root; 00372 category->root = variable; 00373 } else { 00374 for (lineno = 1; lineno < insertline; lineno++) { 00375 cur = cur->next; 00376 if (!cur->next) { 00377 break; 00378 } 00379 } 00380 variable->next = cur->next; 00381 cur->next = variable; 00382 } 00383 }
| struct ast_variable* ast_variable_new | ( | const char * | name, | |
| const char * | value, | |||
| const char * | filename | |||
| ) |
Definition at line 223 of file config.c.
References __ast_calloc(), ast_calloc, and ast_variable::stuff.
Referenced by add_cfg_entry(), add_rt_cfg_entry(), add_rt_multi_cfg_entry(), add_var(), apply_outgoing(), ast_channeltype_list(), ast_variable_update(), astman_get_variables(), build_user(), check_access(), config_curl(), config_ldap(), config_odbc(), config_pgsql(), copy_vars(), create_vmaccount(), handle_updates(), handle_uri(), httpd_helper_thread(), iax_parse_ies(), ldap_table_config_add_attribute(), parkandannounce_exec(), parse_cookies(), process_text_line(), realtime_curl(), realtime_directory(), realtime_ldap_entry_to_var(), realtime_ldap_result_to_vars(), realtime_multi_curl(), realtime_multi_odbc(), realtime_multi_pgsql(), realtime_odbc(), realtime_pgsql(), transmit_notify_custom(), variable_clone(), and vm_change_password().
00225 { 00226 struct ast_variable *variable; 00227 int name_len = strlen(name) + 1; 00228 int val_len = strlen(value) + 1; 00229 int fn_len = strlen(filename) + 1; 00230 00231 #ifdef MALLOC_DEBUG 00232 if ((variable = __ast_calloc(1, name_len + val_len + fn_len + sizeof(*variable), file, lineno, func))) { 00233 #else 00234 if ((variable = ast_calloc(1, name_len + val_len + fn_len + sizeof(*variable)))) { 00235 #endif 00236 char *dst = variable->stuff; /* writable space starts here */ 00237 variable->name = strcpy(dst, name); 00238 dst += name_len; 00239 variable->value = strcpy(dst, value); 00240 dst += val_len; 00241 variable->file = strcpy(dst, filename); 00242 } 00243 return variable; 00244 }
| 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 420 of file config.c.
References ast_variable_browse(), config, ast_variable::name, ast_variable::next, and ast_variable::value.
Referenced by __ast_udptl_reload(), _dsp_init(), advanced_options(), aji_load_config(), ast_config_option(), build_extension(), config_function_read(), config_module(), directory_exec(), do_reload(), do_scheduler(), festival_exec(), function_macro(), get_insecure_variable_from_config(), get_wait_interval(), gtalk_load_config(), iax_template_parse(), init_acf_query(), init_logger_chain(), jingle_load_config(), load_config(), load_config_meetme(), load_indications(), load_module(), load_rpt_vars(), load_tech_calendars(), make_email_file(), node_lookup(), odbc_load_module(), osp_load(), parse_config(), pbx_load_config(), pbx_load_users(), play_message(), prep_email_sub_vars(), private_enum_init(), queue_set_global_params(), read_agent_config(), realtime_directory(), reload_config(), reload_followme(), reload_single_queue(), retreive_memory(), retrieve_astcfgint(), rpt(), rpt_master(), rpt_tele_thread(), rpt_telemetry(), rtp_reload(), saynode(), search_directory(), search_directory_sub(), set_config(), setup_dahdi(), sla_build_station(), sla_build_trunk(), sla_load_config(), tds_load_module(), telem_lookup(), update_realtime_members(), vm_change_password(), and vm_forwardoptions().
00421 { 00422 struct ast_variable *v; 00423 00424 if (category) { 00425 for (v = ast_variable_browse(config, category); v; v = v->next) { 00426 if (!strcasecmp(variable, v->name)) { 00427 return v->value; 00428 } 00429 } 00430 } else { 00431 struct ast_category *cat; 00432 00433 for (cat = config->root; cat; cat = cat->next) { 00434 for (v = cat->root; v; v = v->next) { 00435 if (!strcasecmp(variable, v->name)) { 00436 return v->value; 00437 } 00438 } 00439 } 00440 } 00441 00442 return NULL; 00443 }
| 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 738 of file config.c.
References ast_strlen_zero(), ast_variable_new(), ast_variables_destroy(), ast_variable::blanklines, ast_variable::file, ast_category::last, ast_variable::lineno, ast_variable::name, ast_variable::next, ast_variable::object, ast_variable::precomments, ast_category::root, ast_variable::sameline, ast_variable::trailing, and ast_variable::value.
Referenced by handle_updates(), process_text_line(), vm_change_password(), and vm_forwardoptions().
00740 { 00741 struct ast_variable *cur, *prev=NULL, *newer=NULL; 00742 00743 for (cur = category->root; cur; prev = cur, cur = cur->next) { 00744 if (strcasecmp(cur->name, variable) || 00745 (!ast_strlen_zero(match) && strcasecmp(cur->value, match))) 00746 continue; 00747 00748 if (!(newer = ast_variable_new(variable, value, cur->file))) 00749 return -1; 00750 00751 newer->next = cur->next; 00752 newer->object = cur->object || object; 00753 00754 /* Preserve everything */ 00755 newer->lineno = cur->lineno; 00756 newer->blanklines = cur->blanklines; 00757 newer->precomments = cur->precomments; cur->precomments = NULL; 00758 newer->sameline = cur->sameline; cur->sameline = NULL; 00759 newer->trailing = cur->trailing; cur->trailing = NULL; 00760 00761 if (prev) 00762 prev->next = newer; 00763 else 00764 category->root = newer; 00765 if (category->last == cur) 00766 category->last = newer; 00767 00768 cur->next = NULL; 00769 ast_variables_destroy(cur); 00770 00771 return 0; 00772 } 00773 00774 /* Could not find variable to update */ 00775 return -1; 00776 }
| 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 385 of file config.c.
References ast_free, and ast_variable::next.
Referenced by __sip_destroy(), ast_category_destroy(), ast_category_empty(), ast_http_get_cookies(), ast_pbx_outgoing_app(), ast_pbx_outgoing_exten(), ast_var_channel_types(), ast_var_channel_types_table(), ast_variable_delete(), ast_variable_update(), build_peer(), build_user(), cli_realtime_load(), conf_run(), destroy_dahdi_pvt(), find_conf_realtime(), find_user_realtime(), free_outgoing(), free_user(), handle_uri(), httpd_helper_thread(), httpstatus_callback(), ldap_loadentry(), leave_queue(), load_realtime_queue(), local_ast_moh_start(), manager_sipnotify(), pvt_destructor(), queue_function_queuewaitingcount(), realtime_alias(), realtime_canmatch(), realtime_exists(), realtime_handler(), realtime_ldap_base_ap(), realtime_matchmore(), realtime_odbc(), realtime_peer(), realtime_user(), rt_extend_conf(), sip_destroy_peer(), socket_process(), table_configs_free(), and user_destructor().
00386 { 00387 struct ast_variable *vn; 00388 00389 while (v) { 00390 vn = v; 00391 v = v->next; 00392 ast_free(vn); 00393 } 00394 }
| int config_text_file_save | ( | const char * | filename, | |
| const struct ast_config * | cfg, | |||
| const char * | generator | |||
| ) |
Definition at line 1599 of file config.c.
References ast_config_text_file_save().
01600 { 01601 return ast_config_text_file_save(configfile, cfg, generator); 01602 }
| 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 1892 of file config.c.
References append_mapping(), ast_config_destroy(), ast_config_internal_load(), ast_config_new(), ast_copy_string(), ast_log(), ast_variable_browse(), buf, clear_config_maps(), config, ast_flags::flags, LOG_WARNING, ast_config::max_include_level, ast_variable::name, ast_variable::next, strsep(), table, and ast_variable::value.
Referenced by main().
01893 { 01894 struct ast_config *config, *configtmp; 01895 struct ast_variable *v; 01896 char *driver, *table, *database, *stringp, *tmp; 01897 struct ast_flags flags = { 0 }; 01898 01899 clear_config_maps(); 01900 01901 configtmp = ast_config_new(); 01902 configtmp->max_include_level = 1; 01903 config = ast_config_internal_load(extconfig_conf, configtmp, flags, "", "extconfig"); 01904 if (!config) { 01905 ast_config_destroy(configtmp); 01906 return 0; 01907 } 01908 01909 for (v = ast_variable_browse(config, "settings"); v; v = v->next) { 01910 char buf[512]; 01911 ast_copy_string(buf, v->value, sizeof(buf)); 01912 stringp = buf; 01913 driver = strsep(&stringp, ","); 01914 01915 if ((tmp = strchr(stringp, '\"'))) 01916 stringp = tmp; 01917 01918 /* check if the database text starts with a double quote */ 01919 if (*stringp == '"') { 01920 stringp++; 01921 database = strsep(&stringp, "\""); 01922 strsep(&stringp, ","); 01923 } else { 01924 /* apparently this text has no quotes */ 01925 database = strsep(&stringp, ","); 01926 } 01927 01928 table = strsep(&stringp, ","); 01929 01930 if (!strcmp(v->name, extconfig_conf)) { 01931 ast_log(LOG_WARNING, "Cannot bind '%s'!\n", extconfig_conf); 01932 continue; 01933 } 01934 01935 if (!strcmp(v->name, "asterisk.conf")) { 01936 ast_log(LOG_WARNING, "Cannot bind 'asterisk.conf'!\n"); 01937 continue; 01938 } 01939 01940 if (!strcmp(v->name, "logger.conf")) { 01941 ast_log(LOG_WARNING, "Cannot bind 'logger.conf'!\n"); 01942 continue; 01943 } 01944 01945 if (!driver || !database) 01946 continue; 01947 if (!strcasecmp(v->name, "sipfriends")) { 01948 ast_log(LOG_WARNING, "The 'sipfriends' table is obsolete, update your config to use sipusers and sippeers, though they can point to the same table.\n"); 01949 append_mapping("sipusers", driver, database, table ? table : "sipfriends"); 01950 append_mapping("sippeers", driver, database, table ? table : "sipfriends"); 01951 } else if (!strcasecmp(v->name, "iaxfriends")) { 01952 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"); 01953 append_mapping("iaxusers", driver, database, table ? table : "iaxfriends"); 01954 append_mapping("iaxpeers", driver, database, table ? table : "iaxfriends"); 01955 } else 01956 append_mapping(v->name, driver, database, table); 01957 } 01958 01959 ast_config_destroy(config); 01960 return 0; 01961 }
| 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 2567 of file config.c.
References ARRAY_LEN, ast_cli_register_multiple(), and cli_config.
Referenced by main().
02568 { 02569 ast_cli_register_multiple(cli_config, ARRAY_LEN(cli_config)); 02570 return 0; 02571 }
1.5.1