add patch from MDXMLINT-27

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8418 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2008-05-15 20:29:08 +00:00
parent c599162209
commit 88b177c1b4
4 changed files with 50 additions and 8 deletions

View File

@ -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>

View File

@ -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);
///\}

View File

@ -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;
@ -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,13 +206,16 @@ 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);
@ -244,6 +249,28 @@ 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);
}
}
}
@ -270,6 +297,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");
switch_xml_bind_search_function(xml_url_fetch, switch_xml_parse_section_string(binding->bindings), binding);

View File

@ -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 == '&') {