cleanup xml config handling

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13050 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Rupa Schomaker 2009-04-16 01:32:34 +00:00
parent cb3b46f167
commit 8f66c816b7

View File

@ -67,7 +67,6 @@ static switch_status_t config_callback_memcached(switch_xml_config_item_t *data,
if ((callback_type == CONFIG_LOAD || callback_type == CONFIG_RELOAD) && changed) { if ((callback_type == CONFIG_LOAD || callback_type == CONFIG_RELOAD) && changed) {
memcached_str = *((char**)data->ptr); memcached_str = *((char**)data->ptr);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "memcached data: %s\n", memcached_str);
/* initialize main ptr */ /* initialize main ptr */
memcached_server = memcached_servers_parse(memcached_str); memcached_server = memcached_servers_parse(memcached_str);
@ -79,7 +78,7 @@ static switch_status_t config_callback_memcached(switch_xml_config_item_t *data,
if ((servercount = memcached_server_list_count(memcached_server)) == 0) { if ((servercount = memcached_server_list_count(memcached_server)) == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No memcache servers defined. Server string: %s.\n", memcached_str); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "No memcache servers defined. Server string: %s.\n", memcached_str);
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%u servers defined.\n", servercount); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%u servers defined (%s).\n", servercount, memcached_str);
} }
/* setup memcached */ /* setup memcached */
@ -103,7 +102,6 @@ static switch_status_t config_callback_memcached(switch_xml_config_item_t *data,
switch_goto_status(SWITCH_STATUS_SUCCESS, end); switch_goto_status(SWITCH_STATUS_SUCCESS, end);
end: end:
if (memcached_server) { if (memcached_server) {
memcached_server_list_free(memcached_server); memcached_server_list_free(memcached_server);
@ -117,19 +115,17 @@ end:
return status; return status;
} }
static switch_xml_config_string_options_t config_opt_memcache_servers = {NULL, 0, NULL}; /* anything is ok here */ static switch_xml_config_string_options_t config_opt_memcache_servers = {NULL, 0, NULL}; /* anything ok */
static switch_xml_config_item_t instructions[] = { static switch_xml_config_item_t instructions[] = {
/* parameter name type reloadable pointer default value options structure */ /* parameter name type reloadable pointer default value options structure */
SWITCH_CONFIG_ITEM_CALLBACK("memcache-servers", SWITCH_CONFIG_STRING, CONFIG_REQUIRED | CONFIG_RELOAD, &globals.memcached_str, NULL, config_callback_memcached, &config_opt_memcache_servers, SWITCH_CONFIG_ITEM_CALLBACK("memcache-servers", SWITCH_CONFIG_STRING, CONFIG_REQUIRED | CONFIG_RELOAD, &globals.memcached_str, "", config_callback_memcached, &config_opt_memcache_servers,
"host,host:port,host", "List of memcached servers."), "host,host:port,host", "List of memcached servers."),
SWITCH_CONFIG_ITEM_END() SWITCH_CONFIG_ITEM_END()
}; };
static switch_status_t do_config(switch_bool_t reload) static switch_status_t do_config(switch_bool_t reload)
{ {
memset(&globals, 0, sizeof(globals));
if (switch_xml_config_parse_module_settings("memcache.conf", reload, instructions) != SWITCH_STATUS_SUCCESS) { if (switch_xml_config_parse_module_settings("memcache.conf", reload, instructions) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
@ -141,7 +137,6 @@ static switch_status_t do_config(switch_bool_t reload)
static void event_handler(switch_event_t *event) static void event_handler(switch_event_t *event)
{ {
do_config(SWITCH_TRUE); do_config(SWITCH_TRUE);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Memcache Reloaded\n");
} }
SWITCH_STANDARD_API(memcache_function) SWITCH_STANDARD_API(memcache_function)
@ -342,6 +337,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_memcache_load)
/* connect my internal structure to the blank pointer passed to me */ /* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname); *module_interface = switch_loadable_module_create_module_interface(pool, modname);
memset(&globals, 0, sizeof(globals));
do_config(SWITCH_FALSE); do_config(SWITCH_FALSE);
if ((switch_event_bind_removable(modname, SWITCH_EVENT_RELOADXML, NULL, event_handler, NULL, &NODE) != SWITCH_STATUS_SUCCESS)) { if ((switch_event_bind_removable(modname, SWITCH_EVENT_RELOADXML, NULL, event_handler, NULL, &NODE) != SWITCH_STATUS_SUCCESS)) {