From d53d9d39970689fa13d0ab676b4d7c597951c34b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 12 May 2006 19:28:21 +0000 Subject: [PATCH] rearrange some things please see conf/freeswitch.xml as there is a significant change to the conf that will break your stuff git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1446 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- conf/freeswitch.xml | 88 +++++++++---------- src/include/switch_types.h | 8 ++ src/include/switch_utils.h | 3 +- src/include/switch_xml.h | 8 +- .../mod_dialplan_xml/mod_dialplan_xml.c | 8 +- src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c | 20 +++-- src/switch_xml.c | 51 ++++++++++- 7 files changed, 130 insertions(+), 56 deletions(-) diff --git a/conf/freeswitch.xml b/conf/freeswitch.xml index 843ab974b7..531be3afd1 100644 --- a/conf/freeswitch.xml +++ b/conf/freeswitch.xml @@ -1,6 +1,6 @@ -
+
@@ -205,14 +205,51 @@ - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ @@ -268,46 +305,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+
diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 1e9faf0cea..70da8d0b43 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -93,6 +93,14 @@ SWITCH_DECLARE_DATA extern switch_directories SWITCH_GLOBAL_dirs; #define SWITCH_TRUE 1 #define SWITCH_FALSE 0 + +typedef enum { + SWITCH_XML_SECTION_RESULT = 0, + SWITCH_XML_SECTION_CONFIG = (1 << 0), + SWITCH_XML_SECTION_DIRECTORY = (1 << 1), + SWITCH_XML_SECTION_DIALPLAN = (1 << 2) +} switch_xml_section_t; + /*! \enum switch_vad_flag_t \brief RTP Related Flags diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h index 0841b789cc..6ebae53bcb 100644 --- a/src/include/switch_utils.h +++ b/src/include/switch_utils.h @@ -151,7 +151,8 @@ SWITCH_DECLARE(unsigned char) switch_char_to_rfc2833(char key); \param fname the function name to declare \param vname the name of the global pointer to modify with the new function */ -#define SWITCH_DECLARE_GLOBAL_STRING_FUNC(fname, vname) static void fname(char *string) { if (vname) {free(vname); vname = NULL;}vname = strdup(string);} +#define SWITCH_DECLARE_GLOBAL_STRING_FUNC(fname, vname) static void fname(char *string) { if (!string) return;\ +if (vname) {free(vname); vname = NULL;}vname = strdup(string);} /*! \brief Separate a string into an array based on a character delimeter diff --git a/src/include/switch_xml.h b/src/include/switch_xml.h index 26eedb3483..97a49e078c 100644 --- a/src/include/switch_xml.h +++ b/src/include/switch_xml.h @@ -313,9 +313,15 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_open_cfg(char *file_path, switch_xml_t * ///\brief bind a search function to an external gateway ///\param function the search function to bind +///\param sections a bitmask of sections you wil service ///\return SWITCH_STATUS_SUCCESS if successful ///\note gateway functions will be executed in the order they were binded until a success is found else the root registry will be used -SWITCH_DECLARE(switch_status_t) switch_xml_bind_search_function(switch_xml_search_function_t function); +SWITCH_DECLARE(switch_status_t) switch_xml_bind_search_function(switch_xml_search_function_t function, switch_xml_section_t sections); + +///\brief parse a string for a list of sections +///\param string a | delimited list of section names +///\return the section mask +SWITCH_DECLARE(switch_xml_section_t) switch_xml_parse_section_string(char *str); END_EXTERN_C diff --git a/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c b/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c index a64e3b4157..f8ede626ce 100644 --- a/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c +++ b/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c @@ -127,7 +127,6 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session) switch_caller_profile_t *caller_profile; switch_caller_extension_t *extension = NULL; switch_channel_t *channel; - char *cf = "extensions.conf"; char *exten_name = NULL; switch_xml_t cfg, xml, xcontext, xexten, xaction, xcond; char *context = NULL; @@ -145,10 +144,11 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session) caller_profile->destination_number); snprintf(params, sizeof(params), "dest=%s", caller_profile->destination_number); - if (!(xml = switch_xml_open_cfg(cf, &cfg, params))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); + + if (switch_xml_locate("dialplan", NULL, NULL, NULL, &xml, &cfg, params) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of dialplan failed\n"); switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); - return NULL; + return NULL; } if (!(xcontext = switch_xml_find_child(cfg, "context", "name", context))) { diff --git a/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c b/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c index 5b19ac0676..43ee569827 100644 --- a/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c +++ b/src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c @@ -49,9 +49,11 @@ static struct { uint16_t port; uint8_t running; char *url; + char *bindings; } globals; -SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_url, globals.url) +SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_url, globals.url); +SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_bindings, globals.bindings); struct config_data { char *name; @@ -79,8 +81,14 @@ static switch_xml_t xml_url_fetch(char *section, struct config_data config_data; switch_xml_t xml = NULL; - snprintf(url, sizeof(url), "%s?section=%s&tag_name=%s&key_name=%s&key_value=%s%s%s\n", - globals.url, section, tag_name, key_name, key_value, params ? "&" : "", params ? params : ""); + snprintf(url, sizeof(url), "%s?section=%s&tag_name=%s&key_name=%s&&key_value=%s%s%s\n", + globals.url, + section, + tag_name ? tag_name : "", + key_name ? key_name : "", + key_value ? key_value : "", + params ? "&" : "", params ? params : ""); + srand((unsigned int)(time(NULL) + strlen(url))); snprintf(filename, sizeof(filename), "%s%04x.tmp", SWITCH_GLOBAL_dirs.temp_dir, (rand() & 0xffff)); curl_handle = curl_easy_init(); @@ -142,6 +150,8 @@ static switch_status_t do_config(void) char *val = (char *) switch_xml_attr(param, "value"); if (!strcasecmp(var, "gateway_url")) { + char *bindings = (char *) switch_xml_attr(param, "bindings"); + set_global_bindings(bindings); set_global_url(val); } else if (!strcasecmp(var, "http_port")) { globals.port = (uint16_t)atoi(val); @@ -167,8 +177,8 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod memset(&globals, 0, sizeof(globals)); if (do_config() == SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Binding XML Fetch Function [%s]\n", globals.url); - switch_xml_bind_search_function(xml_url_fetch); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Binding XML Fetch Function [%s] [%s]\n", globals.url, globals.bindings ? globals.bindings : "all"); + switch_xml_bind_search_function(xml_url_fetch, switch_xml_parse_section_string(globals.bindings)); } curl_global_init(CURL_GLOBAL_ALL); diff --git a/src/switch_xml.c b/src/switch_xml.c index ef17e897f4..d8d9126c82 100644 --- a/src/switch_xml.c +++ b/src/switch_xml.c @@ -84,6 +84,7 @@ char *SWITCH_XML_NIL[] = { NULL }; // empty, null terminated array of strings struct switch_xml_binding { switch_xml_search_function_t function; + switch_xml_section_t sections; struct switch_xml_binding *next; }; @@ -94,7 +95,43 @@ static switch_memory_pool_t *XML_MEMORY_POOL; static switch_mutex_t *XML_LOCK; static switch_thread_rwlock_t *RWLOCK; -SWITCH_DECLARE(switch_status_t) switch_xml_bind_search_function(switch_xml_search_function_t function) +struct xml_section_t { + const char *name; + switch_xml_section_t section; +}; + + +static struct xml_section_t SECTIONS[] = { + { "result", SWITCH_XML_SECTION_RESULT}, + { "config", SWITCH_XML_SECTION_CONFIG}, + { "directory", SWITCH_XML_SECTION_DIRECTORY}, + { "dialplan", SWITCH_XML_SECTION_DIALPLAN}, + { NULL, 0} +}; + +SWITCH_DECLARE(switch_xml_section_t) switch_xml_parse_section_string(char *str) +{ + int x; + char buf[1024] = ""; + switch_xml_section_t sections = SWITCH_XML_SECTION_RESULT; + + if (str) { + for(x = 0; x < strlen(str); x++) { + buf[x] = tolower(str[x]); + } + for(x = 0;;x++) { + if (!SECTIONS[x].name) { + break; + } + if (strstr(buf, SECTIONS[x].name)) { + sections |= SECTIONS[x].section; + } + } + } + return sections; +} + +SWITCH_DECLARE(switch_status_t) switch_xml_bind_search_function(switch_xml_search_function_t function, switch_xml_section_t sections) { switch_xml_binding_t *binding = NULL, *ptr = NULL; assert(function != NULL); @@ -104,6 +141,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_bind_search_function(switch_xml_searc } binding->function = function; + binding->sections = sections; switch_mutex_lock(XML_LOCK); for (ptr = BINDINGS; ptr && ptr->next; ptr = ptr->next); @@ -123,8 +161,13 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_find_child(switch_xml_t node, char *chil { switch_xml_t p = NULL; + if (!(childname && attrname && value)) { + return node; + } + for (p = switch_xml_child(node, childname); p; p = p->next) { const char *aname = switch_xml_attr(p, attrname); + if (!strcasecmp(aname, value)) { break; } @@ -757,6 +800,12 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate(char *section, switch_mutex_lock(XML_LOCK); for(binding = BINDINGS; binding; binding = binding->next) { + switch_xml_section_t sections = switch_xml_parse_section_string(section); + + if (binding->sections && !(sections & binding->sections)) { + continue; + } + if ((xml = binding->function(section, tag_name, key_name, key_value, params))) { const char *err = NULL;