diff --git a/conf/autoload_configs/xml_rpc.conf.xml b/conf/autoload_configs/xml_rpc.conf.xml index 714a909907..4b285079f9 100644 --- a/conf/autoload_configs/xml_rpc.conf.xml +++ b/conf/autoload_configs/xml_rpc.conf.xml @@ -6,5 +6,7 @@ <param name="auth-realm" value="freeswitch"/> <param name="auth-user" value="freeswitch"/> <param name="auth-pass" value="works"/> + <!-- one or more of these imply you want to pick the exact variables that are transmitted --> + <!--<param name="enable-post-var" value="Unique-ID"/>--> </settings> </configuration> diff --git a/src/include/switch_event.h b/src/include/switch_event.h index 827fa9fb0c..944a488eaa 100644 --- a/src/include/switch_event.h +++ b/src/include/switch_event.h @@ -339,7 +339,7 @@ SWITCH_DECLARE(void) switch_event_deliver(switch_event_t **event); */ #define switch_event_fire_data(event, data) switch_event_fire_detailed(__FILE__, (char * )__SWITCH_FUNC__, __LINE__, event, data) -SWITCH_DECLARE(char *) switch_event_build_param_string(switch_event_t *event, const char *prefix); +SWITCH_DECLARE(char *) switch_event_build_param_string(switch_event_t *event, const char *prefix,switch_hash_t* vars_map); ///\} diff --git a/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c b/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c index 71b9c200fd..45a8f1e7e7 100644 --- a/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c +++ b/src/mod/xml_int/mod_xml_curl/mod_xml_curl.c @@ -43,6 +43,8 @@ struct xml_binding { char *cred; int disable100continue; uint32_t ignore_cacert_check; + switch_hash_t* vars_map; + switch_memory_pool_t* vars_map_pool; }; static int keep_files_around = 0; @@ -110,7 +112,7 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con struct curl_slist *headers = NULL; char hostname[256] = ""; char basic_data[512]; - + gethostname(hostname, sizeof(hostname)); if (!binding) { @@ -134,7 +136,7 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con switch_str_nil(key_name), switch_str_nil(key_value)); - data = switch_event_build_param_string(params, basic_data); + data = switch_event_build_param_string(params, basic_data,binding->vars_map); switch_assert(data); switch_uuid_get(&uuid); @@ -204,14 +206,17 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con return xml; } - +#define ENABLE_PARAM_VALUE "enabled" static switch_status_t do_config(void) { char *cf = "xml_curl.conf"; switch_xml_t cfg, xml, bindings_tag, binding_tag, param; xml_binding_t *binding = NULL; int x = 0; - + int need_vars_map = 0; + switch_hash_t* vars_map = NULL; + switch_memory_pool_t* vars_map_pool = NULL; + if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); return SWITCH_STATUS_TERM; @@ -244,7 +249,29 @@ static switch_status_t do_config(void) disable100continue = 1; } else if (!strcasecmp(var, "ignore-cacert-check") && switch_true(val)) { ignore_cacert_check = 1; - } + } else if(!strcasecmp(var, "enable-post-var")) { + if (!vars_map && need_vars_map == 0) { + if (switch_core_new_memory_pool(&vars_map_pool) != SWITCH_STATUS_SUCCESS) { + need_vars_map = -1; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cant create memory pool!\n"); + continue; + } + + if (switch_core_hash_init(&vars_map,vars_map_pool) != SWITCH_STATUS_SUCCESS) { + need_vars_map = -1; + switch_core_destroy_memory_pool(&vars_map_pool); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cant init params hash!\n"); + continue; + } + need_vars_map = 1; + } + + if(vars_map) + if (switch_core_hash_insert(vars_map,val,ENABLE_PARAM_VALUE) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cant add %s to params hash!\n",val); + } + + } } if (!url) { @@ -269,6 +296,9 @@ static switch_status_t do_config(void) binding->disable100continue = disable100continue; binding->ignore_cacert_check = ignore_cacert_check; + + binding->vars_map = vars_map; + binding->vars_map_pool = vars_map_pool; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Binding [%s] XML Fetch Function [%s] [%s]\n", switch_strlen_zero(bname) ? "N/A" : bname, binding->url, binding->bindings ? binding->bindings : "all"); diff --git a/src/switch_event.c b/src/switch_event.c index 50bab12d5e..03d0eddac7 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -1275,7 +1275,7 @@ SWITCH_DECLARE(char *) switch_event_expand_headers(switch_event_t *event, const return data; } -SWITCH_DECLARE(char *) switch_event_build_param_string(switch_event_t *event, const char *prefix) +SWITCH_DECLARE(char *) switch_event_build_param_string(switch_event_t *event, const char *prefix, switch_hash_t* vars_map) { switch_stream_handle_t stream = { 0 }; switch_size_t encode_len = 1024, new_len = 0; @@ -1284,6 +1284,7 @@ SWITCH_DECLARE(char *) switch_event_build_param_string(switch_event_t *event, co char *e = NULL; switch_event_header_t *hi; uint32_t x = 0; + void* data = NULL; SWITCH_STANDARD_STREAM(stream); @@ -1318,10 +1319,18 @@ SWITCH_DECLARE(char *) switch_event_build_param_string(switch_event_t *event, co if (event) { if ((hi = event->headers)) { + for (; hi; hi = hi->next) { char *var = hi->name; char *val = hi->value; - + + if (vars_map != NULL) + { + if ((data = switch_core_hash_find(vars_map,var)) == NULL || strcasecmp(((char*)data),"enabled")) + continue; + + } + new_len = (strlen((char *) var) * 3) + 1; if (encode_len < new_len) { char *tmp; @@ -1339,6 +1348,7 @@ SWITCH_DECLARE(char *) switch_event_build_param_string(switch_event_t *event, co } } } + e = (char *) stream.data + (strlen((char *) stream.data) - 1); if (e && *e == '&') {