change xml_lookups to take an event as params instead of url string this will break your xml_curl scripts please update

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7333 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2008-01-23 20:59:25 +00:00
parent 14ba0b9999
commit 1424b6c73b
16 changed files with 286 additions and 103 deletions

View File

@ -336,6 +336,9 @@ SWITCH_DECLARE(void) switch_event_deliver(switch_event_t **event);
\note the body supplied by this function will supersede an existing body the event may have
*/
#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_END_EXTERN_C

View File

@ -1162,7 +1162,7 @@ typedef switch_status_t (*switch_say_callback_t) (switch_core_session_t *session
typedef struct switch_xml *switch_xml_t;
typedef struct switch_core_time_duration switch_core_time_duration_t;
typedef switch_xml_t(*switch_xml_search_function_t) (const char *section,
const char *tag_name, const char *key_name, const char *key_value, const char *params,
const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params,
void *user_data);
typedef struct switch_hash switch_hash_t;

View File

@ -316,9 +316,9 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_root(void);
SWITCH_DECLARE(switch_status_t) switch_xml_locate(const char *section,
const char *tag_name,
const char *key_name, const char *key_value, switch_xml_t * root, switch_xml_t * node,
const char *params);
switch_event_t *params);
SWITCH_DECLARE(switch_status_t) switch_xml_locate_domain(const char *domain_name, char *params, switch_xml_t *root, switch_xml_t *domain);
SWITCH_DECLARE(switch_status_t) switch_xml_locate_domain(const char *domain_name, switch_event_t *params, switch_xml_t *root, switch_xml_t *domain);
SWITCH_DECLARE(switch_status_t) switch_xml_locate_user(const char *key,
const char *user_name,
const char *domain_name,
@ -326,14 +326,14 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate_user(const char *key,
switch_xml_t *root,
switch_xml_t *domain,
switch_xml_t *user,
const char *xtra_params);
switch_event_t *params);
///\brief open a config in the core registry
///\param file_path the name of the config section e.g. modules.conf
///\param node a pointer to point to the node if it is found
///\param params optional URL formatted params to pass to external gateways
///\return the root xml node associated with the current request or NULL
SWITCH_DECLARE(switch_xml_t) switch_xml_open_cfg(const char *file_path, switch_xml_t * node, const char *params);
SWITCH_DECLARE(switch_xml_t) switch_xml_open_cfg(const char *file_path, switch_xml_t * node, switch_event_t *params);
///\brief bind a search function to an external gateway
///\param function the search function to bind

View File

@ -50,7 +50,7 @@ SWITCH_STANDARD_API(user_data_function)
char delim = ' ';
const char *err = NULL;
const char *container = "params", *elem = "param";
char *params = NULL;
switch_event_t *params = NULL;
if (!cmd) {
err = "bad args";
@ -77,7 +77,13 @@ SWITCH_STANDARD_API(user_data_function)
domain = "cluecon.com";
}
params = switch_mprintf("user=%s&domain=%s&type=%s&key=%s", user, domain, type, key);
switch_event_create(&params, SWITCH_EVENT_MESSAGE);
switch_assert(params);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "user", user);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "domain", domain);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "type", type);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "key", key);
if (switch_xml_locate_user("id", user, domain, NULL, &xml, &x_domain, &x_user, params) != SWITCH_STATUS_SUCCESS) {
err = "can't find user";
@ -87,6 +93,9 @@ SWITCH_STANDARD_API(user_data_function)
end:
switch_event_destroy(&params);
if (xml) {
if (err) {
//stream->write_function(stream, "-Error %s\n", err);
@ -217,7 +226,8 @@ SWITCH_STANDARD_API(xml_locate_function)
switch_xml_t xml = NULL, obj = NULL;
int argc;
char *mydata = NULL, *argv[4];
char *section, *tag, *tag_attr_name, *tag_attr_val, *params = NULL;
char *section, *tag, *tag_attr_name, *tag_attr_val;
switch_event_t *params = NULL;
char *xmlstr;
char *path_info, delim = ' ';
char *host = NULL;
@ -259,8 +269,13 @@ SWITCH_STANDARD_API(xml_locate_function)
tag_attr_name = argv[2];
tag_attr_val = argv[3];
params = switch_mprintf("section=%s&tag=%s&tag_attr_name=%s&tag_attr_val=%s", section, tag, tag_attr_name, tag_attr_val);
switch_event_create(&params, SWITCH_EVENT_MESSAGE);
switch_assert(params);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "section", section);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "tag", tag);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "tag_attr_name", tag_attr_name);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "tag_attr_val", tag_attr_val);
if (switch_xml_locate(section, tag, tag_attr_name, tag_attr_val, &xml, &obj, params) != SWITCH_STATUS_SUCCESS) {
stream->write_function(stream, "can't find anything\n");
goto end;
@ -269,6 +284,8 @@ SWITCH_STANDARD_API(xml_locate_function)
end:
switch_event_destroy(&params);
if (err) {
if (host) {
stream->write_function(stream, "<error>%s</error>\n", err);

View File

@ -3187,7 +3187,7 @@ static switch_status_t conf_api_sub_bgdial(conference_obj_t * conference, switch
static switch_status_t conf_api_sub_transfer(conference_obj_t * conference, switch_stream_handle_t *stream, int argc, char **argv)
{
switch_status_t ret_status = SWITCH_STATUS_SUCCESS;
char *params = NULL, *chanvars = NULL;
switch_event_t *params = NULL;
switch_assert(conference != NULL);
switch_assert(stream != NULL);
@ -3229,10 +3229,15 @@ static switch_status_t conf_api_sub_transfer(conference_obj_t * conference, swit
} else {
profile_name = "default";
}
params = switch_mprintf("conf_name=%s&profile_name=%s", conf_name, profile_name);
chanvars = switch_channel_build_param_string(channel, NULL, params);
switch_event_create(&params, SWITCH_EVENT_MESSAGE);
switch_assert(params);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "conf_name", conf_name);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "profile_name", profile_name);
switch_channel_event_set_data(channel, params);
/* Open the config from the xml registry */
if (!(cxml = switch_xml_open_cfg(global_cf_name, &cfg, chanvars))) {
if (!(cxml = switch_xml_open_cfg(global_cf_name, &cfg, params))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", global_cf_name);
goto done;
}
@ -3303,9 +3308,9 @@ static switch_status_t conf_api_sub_transfer(conference_obj_t * conference, swit
}
done:
switch_safe_free(params);
switch_safe_free(chanvars);
if (params) {
switch_event_destroy(&params);
}
return ret_status;
}
@ -3980,7 +3985,7 @@ SWITCH_STANDARD_APP(conference_function)
uint8_t rl = 0, isbr = 0;
char *dpin = NULL;
conf_xml_cfg_t xml_cfg = { 0 };
char *params = NULL;
switch_event_t *params = NULL;
switch_assert(channel != NULL);
@ -4032,7 +4037,11 @@ SWITCH_STANDARD_APP(conference_function)
profile_name = "default";
}
params = switch_mprintf("conf_name=%s&profile_name=%s", conf_name, profile_name);
switch_event_create(&params, SWITCH_EVENT_MESSAGE);
switch_assert(params);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "conf_name", conf_name);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "profile_name", profile_name);
/* Open the config from the xml registry */
if (!(cxml = switch_xml_open_cfg(global_cf_name, &cfg, params))) {
@ -4337,7 +4346,7 @@ SWITCH_STANDARD_APP(conference_function)
codec_done2:
switch_core_codec_destroy(&member.write_codec);
done:
switch_safe_free(params);
switch_event_destroy(&params);
switch_buffer_destroy(&member.resample_buffer);
switch_buffer_destroy(&member.audio_buffer);
switch_buffer_destroy(&member.mux_buffer);
@ -4957,9 +4966,15 @@ static void pres_event_handler(switch_event_t *event)
static void send_presence(switch_event_types_t id)
{
switch_xml_t cxml, cfg, advertise, room;
switch_event_t *params = NULL;
switch_event_create(&params, SWITCH_EVENT_MESSAGE);
switch_assert(params);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "presence", "true");
/* Open the config from the xml registry */
if (!(cxml = switch_xml_open_cfg(global_cf_name, &cfg, "presence"))) {
if (!(cxml = switch_xml_open_cfg(global_cf_name, &cfg, params))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", global_cf_name);
goto done;
}
@ -4983,6 +4998,8 @@ static void send_presence(switch_event_types_t id)
}
done:
switch_event_destroy(&params);
/* Release the config registry handle */
if (cxml) {
switch_xml_free(cxml);

View File

@ -864,16 +864,19 @@ static switch_ivr_action_t menu_handler(switch_ivr_menu_t * menu, char *param, c
SWITCH_STANDARD_APP(ivr_application_function)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
char *params,*chanvars;
if (channel && !switch_strlen_zero(data) && (params = switch_core_session_strdup(session, data))) {
switch_event_t *params;
if (channel) {
switch_xml_t cxml = NULL, cfg = NULL, xml_menus = NULL, xml_menu = NULL;
// Open the config from the xml registry
chanvars = switch_channel_build_param_string(channel, NULL, NULL);
if ((cxml = switch_xml_open_cfg(ivr_cf_name, &cfg, chanvars)) != NULL) {
switch_event_create(&params, SWITCH_EVENT_MESSAGE);
switch_assert(params);
switch_channel_event_set_data(channel, params);
if ((cxml = switch_xml_open_cfg(ivr_cf_name, &cfg, params)) != NULL) {
if ((xml_menus = switch_xml_child(cfg, "menus"))) {
xml_menu = switch_xml_find_child(xml_menus, "menu", "name", params);
xml_menu = switch_xml_find_child(xml_menus, "menu", "name", (char *)data);
// if the menu was found
if (xml_menu != NULL) {
@ -889,20 +892,20 @@ SWITCH_STANDARD_APP(ivr_application_function)
switch_xml_free(cxml);
cxml = NULL;
switch_channel_pre_answer(channel);
switch_ivr_menu_execute(session, menu_stack, params, NULL);
switch_ivr_menu_execute(session, menu_stack, (char *)data, NULL);
switch_ivr_menu_stack_free(menu_stack);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to create menu '%s'\n", params);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to create menu\n");
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to find menu '%s'\n", params);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to find menu\n");
}
}
switch_xml_free(cxml);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", ivr_cf_name);
}
switch_safe_free(chanvars);
switch_event_destroy(&params);
}
}
@ -1414,7 +1417,7 @@ static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session,
static switch_call_cause_t cause = SWITCH_CAUSE_UNALLOCATED;
unsigned int timelimit = 60;
switch_channel_t *new_channel = NULL;
switch_event_t *params;
if (switch_strlen_zero(outbound_profile->destination_number)) {
goto done;
}
@ -1427,7 +1430,12 @@ static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session,
*domain++ = '\0';
if (switch_xml_locate_user("id", user, domain, NULL, &xml, &x_domain, &x_user, "as_channel=true") != SWITCH_STATUS_SUCCESS) {
switch_event_create(&params, SWITCH_EVENT_MESSAGE);
switch_assert(params);
switch_event_add_header(params, SWITCH_STACK_BOTTOM, "as_channel", "true");
if (switch_xml_locate_user("id", user, domain, NULL, &xml, &x_domain, &x_user, params) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", user, domain);
goto done;
}
@ -1458,6 +1466,8 @@ static switch_call_cause_t user_outgoing_channel(switch_core_session_t *session,
done:
switch_event_destroy(&params);
if (dest) {
const char *var;
char *d_dest = NULL;

View File

@ -1562,20 +1562,24 @@ case VM_CHECK_AUTH:
}
if (!x_user) {
char *xtra;
switch_event_t *params;
int ok = 1;
caller_profile = switch_channel_get_caller_profile(channel);
xtra = switch_mprintf("mailbox=%s&destination_number=%s&caller_id_number=%s",
myid,caller_profile->destination_number,caller_profile->caller_id_number);
switch_assert(xtra);
switch_event_create(&params, SWITCH_EVENT_MESSAGE);
switch_assert(params);
switch_event_add_header(params, SWITCH_STACK_BOTTOM, "mailbox", myid);
switch_event_add_header(params, SWITCH_STACK_BOTTOM, "destination_number", caller_profile->destination_number);
switch_event_add_header(params, SWITCH_STACK_BOTTOM, "caller_id_number", caller_profile->caller_id_number);
if (switch_xml_locate_user("id", myid, domain_name, switch_channel_get_variable(channel, "network_addr"),
&x_domain_root, &x_domain, &x_user, xtra) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", myid, domain_name);
ok = 0;
&x_domain_root, &x_domain, &x_user, params) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", myid, domain_name);
ok = 0;
}
switch_safe_free(xtra);
switch_event_destroy(&params);
if (!ok) {
goto end;
@ -1742,16 +1746,19 @@ static switch_status_t voicemail_leave_main(switch_core_session_t *session, cons
if (id) {
int ok = 1;
char *xtra = switch_mprintf("mailbox=%s", id);
switch_event_t *params = NULL;
switch_xml_t x_domain, x_domain_root, x_user, x_params, x_param;
const char *email_addr = NULL;
switch_assert(xtra);
switch_event_create(&params, SWITCH_EVENT_MESSAGE);
switch_assert(params);
switch_event_add_header(params, SWITCH_STACK_BOTTOM, "mailbox", id);
x_user = x_domain = x_domain_root = NULL;
if (switch_xml_locate_user("id", id, domain_name, switch_channel_get_variable(channel, "network_addr"),
&x_domain_root, &x_domain, &x_user, xtra) == SWITCH_STATUS_SUCCESS) {
if ((x_params = switch_xml_child(x_user, "params"))) {
for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
&x_domain_root, &x_domain, &x_user, params) == SWITCH_STATUS_SUCCESS) {
if ((x_params = switch_xml_child(x_user, "params"))) {
for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
const char *var = switch_xml_attr_soft(x_param, "name");
const char *val = switch_xml_attr_soft(x_param, "value");
@ -1778,7 +1785,7 @@ static switch_status_t voicemail_leave_main(switch_core_session_t *session, cons
ok = 0;
}
switch_safe_free(xtra);
switch_event_destroy(&params);
switch_xml_free(x_domain_root);
if (!ok) {
goto end;

View File

@ -181,15 +181,18 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
static switch_status_t dialplan_xml_locate(switch_core_session_t *session, switch_caller_profile_t *caller_profile, switch_xml_t * root,
switch_xml_t * node)
{
char *data;
switch_channel_t *channel;
switch_status_t status = SWITCH_STATUS_GENERR;
switch_event_t *params = NULL;
channel = switch_core_session_get_channel(session);
data = switch_channel_build_param_string(channel, caller_profile, NULL);
switch_event_create(&params, SWITCH_EVENT_MESSAGE);
switch_assert(params);
status = switch_xml_locate("dialplan", NULL, NULL, NULL, root, node, data);
switch_safe_free(data);
switch_channel_event_set_data(channel, params);
status = switch_xml_locate("dialplan", NULL, NULL, NULL, root, node, params);
switch_event_destroy(&params);
return status;
}

View File

@ -2278,7 +2278,8 @@ static switch_status_t load_config(void)
static void do_vcard(ldl_handle_t *handle, char *to, char *from, char *id)
{
char *params = NULL, *real_to, *to_user, *xmlstr = NULL, *to_host = NULL;
switch_event_t *params = NULL;
char *real_to, *to_user, *xmlstr = NULL, *to_host = NULL;
switch_xml_t domain, xml = NULL, user, vcard;
int sent = 0;
@ -2303,11 +2304,11 @@ static void do_vcard(ldl_handle_t *handle, char *to, char *from, char *id)
goto end;
}
if (!(params = switch_mprintf("to=%s@%s&from=%s&object=vcard", to_user, to_host, from))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
goto end;
}
switch_event_create(&params, SWITCH_EVENT_MESSAGE);
switch_assert(params);
switch_event_add_header(params, SWITCH_STACK_BOTTOM, "to", "%s@%s", to_user, to_host);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "from", from);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "object", "vcard");
if (switch_xml_locate("directory", "domain", "name", to_host, &xml, &domain, params) != SWITCH_STATUS_SUCCESS) {
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "can't find domain for [%s@%s]\n", to_user, to_host);
@ -2335,6 +2336,8 @@ static void do_vcard(ldl_handle_t *handle, char *to, char *from, char *id)
end:
switch_event_destroy(&params);
if (!sent) {
ldl_handle_send_vcard(handle, to, from, id, NULL);
}

View File

@ -828,7 +828,8 @@ switch_status_t config_sofia(int reload, char *profile_name)
sofia_profile_t *profile = NULL;
char url[512] = "";
int profile_found = 0;
switch_event_t *params = NULL;;
if (!reload) {
su_init();
if (sip_update_default_mclass(sip_extend_mclass(NULL)) < 0) {
@ -847,9 +848,11 @@ switch_status_t config_sofia(int reload, char *profile_name)
return status;
}
switch_snprintf(url, sizeof(url), "profile=%s", switch_str_nil(profile_name));
if (!(xml = switch_xml_open_cfg(cf, &cfg, url))) {
switch_event_create(&params, SWITCH_EVENT_MESSAGE);
switch_assert(params);
switch_event_add_header(params, SWITCH_STACK_BOTTOM, "profile", profile_name);
if (!(xml = switch_xml_open_cfg(cf, &cfg, params))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
status = SWITCH_STATUS_FALSE;
goto done;
@ -1279,6 +1282,9 @@ switch_status_t config_sofia(int reload, char *profile_name)
}
}
done:
switch_event_destroy(&params);
if (xml) {
switch_xml_free(xml);
}

View File

@ -775,8 +775,8 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
char *mailbox = NULL;
switch_xml_t domain, xml = NULL, user, param, uparams, dparams;
char hexdigest[2 * SU_MD5_DIGEST_SIZE + 1] = "";
char *pbuf = NULL;
char *domain_name = NULL;
switch_event_t *params = NULL;
username = realm = nonce = uri = qop = cnonce = nc = response = NULL;
@ -854,9 +854,12 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
free(sql);
}
pbuf = switch_mprintf("action=sip_auth&profile=%s&user_agent=%s",
profile->name,
(sip && sip->sip_user_agent) ? sip->sip_user_agent->g_string : "unknown");
switch_event_create(&params, SWITCH_EVENT_MESSAGE);
switch_assert(params);
switch_event_add_header(params, SWITCH_STACK_BOTTOM, "action", "sip_auth");
switch_event_add_header(params, SWITCH_STACK_BOTTOM, "profile", profile->name);
switch_event_add_header(params, SWITCH_STACK_BOTTOM, "user_agent", (sip && sip->sip_user_agent) ? sip->sip_user_agent->g_string : "unknown");
if (!switch_strlen_zero(profile->reg_domain)) {
domain_name = profile->reg_domain;
@ -864,7 +867,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
domain_name = realm;
}
if (switch_xml_locate_user("id", username, domain_name, ip, &xml, &domain, &user, pbuf) != SWITCH_STATUS_SUCCESS) {
if (switch_xml_locate_user("id", username, domain_name, ip, &xml, &domain, &user, params) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", username, domain_name);
ret = AUTH_FORBIDDEN;
goto end;
@ -1053,10 +1056,13 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t co
}
}
end:
switch_event_destroy(&params);
if (xml) {
switch_xml_free(xml);
}
switch_safe_free(pbuf);
switch_safe_free(input);
switch_safe_free(input2);
switch_safe_free(username);

View File

@ -95,7 +95,7 @@ static size_t file_callback(void *ptr, size_t size, size_t nmemb, void *data)
}
static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, const char *key_name, const char *key_value, const char *params,
static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, const char *key_name, const char *key_value, switch_event_t *params,
void *user_data)
{
char filename[512] = "";
@ -111,7 +111,8 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con
long httpRes = 0;
struct curl_slist *headers = NULL;
char hostname[256] = "";
char basic_data[512];
gethostname(hostname, sizeof(hostname));
if (!binding) {
@ -128,15 +129,18 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con
return xml;
}
data = switch_mprintf("hostname=%s&section=%s&tag_name=%s&key_name=%s&key_value=%s%s%s",
hostname,
section,
switch_str_nil(tag_name),
switch_str_nil(key_name),
switch_str_nil(key_value),
params ? strchr(params, '=') ? "&" : "&params=" : "", params ? params : "");
switch_assert(data);
switch_snprintf(basic_data, sizeof(basic_data), "hostname=%s&section=%s&tag_name=%s&key_name=%s&key_value=%s",
hostname,
section,
switch_str_nil(tag_name),
switch_str_nil(key_name),
switch_str_nil(key_value));
data = switch_event_build_param_string(params, basic_data);
switch_assert(data);
printf("XXXXXXXXXXXXXXXXXXXX\n%s\n", data);
switch_uuid_get(&uuid);
switch_uuid_format(uuid_str, &uuid);

View File

@ -158,6 +158,7 @@ static abyss_bool http_directory_auth(TSession *r, char *domain_name)
switch_xml_t x_domain, x_domain_root = NULL, x_user, x_params, x_param;
const char *box;
int at = 0;
switch_event_t *params = NULL;
p = RequestHeaderValue(r, "authorization");
@ -197,11 +198,17 @@ static abyss_bool http_directory_auth(TSession *r, char *domain_name)
r->user=strdup(user);
goto authed;
}
switch_event_create(&params, SWITCH_EVENT_MESSAGE);
switch_assert(params);
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "mailbox", "check");
if (switch_xml_locate_user("id", user, domain_name, NULL, &x_domain_root, &x_domain, &x_user, "mailbox=check") != SWITCH_STATUS_SUCCESS) {
if (switch_xml_locate_user("id", user, domain_name, NULL, &x_domain_root, &x_domain, &x_user, params) != SWITCH_STATUS_SUCCESS) {
switch_event_destroy(&params);
goto fail;
}
switch_event_destroy(&params);
box = switch_xml_attr_soft(x_user, "mailbox");
for (x_param = switch_xml_child(x_domain, "param"); x_param; x_param = x_param->next) {

View File

@ -1268,6 +1268,81 @@ 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_stream_handle_t stream = { 0 };
switch_size_t encode_len = 1024, new_len = 0;
char *encode_buf = NULL;
const char *prof[12] = { 0 }, *prof_names[12] = {0};
char *e = NULL;
switch_event_header_t *hi;
uint32_t x = 0;
SWITCH_STANDARD_STREAM(stream);
if (prefix) {
stream.write_function(&stream, "%s&", prefix);
}
encode_buf = malloc(encode_len);
switch_assert(encode_buf);
for (x = 0; prof[x]; x++) {
if (switch_strlen_zero(prof[x])) {
continue;
}
new_len = (strlen(prof[x]) * 3) + 1;
if (encode_len < new_len) {
char *tmp;
encode_len = new_len;
if (!(tmp = realloc(encode_buf, encode_len))) {
abort();
}
encode_buf = tmp;
}
switch_url_encode(prof[x], encode_buf, encode_len - 1);
stream.write_function(&stream, "%s=%s&", prof_names[x], encode_buf);
}
if ((hi = event->headers)) {
for (; hi; hi = hi->next) {
char *var = hi->name;
char *val = hi->value;
new_len = (strlen((char *) var) * 3) + 1;
if (encode_len < new_len) {
char *tmp;
encode_len = new_len;
tmp = realloc(encode_buf, encode_len);
switch_assert(tmp);
encode_buf = tmp;
}
switch_url_encode((char *) val, encode_buf, encode_len - 1);
stream.write_function(&stream, "%s=%s&", (char *) var, encode_buf);
}
}
e = (char *) stream.data + (strlen((char *) stream.data) - 1);
if (e && *e == '&') {
*e = '\0';
}
switch_safe_free(encode_buf);
return stream.data;
}
/* For Emacs:
* Local Variables:
* mode:c

View File

@ -93,8 +93,9 @@ static switch_say_type_t get_say_type_by_name(char *name)
SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *session, const char *macro_name, const char *data, const char *lang,
switch_input_args_t *args)
{
switch_event_t *hint_data;
switch_xml_t cfg, xml = NULL, language, macros, macro, input, action;
char *lname = NULL, *mname = NULL, hint_data[1024] = "", enc_hint[1024] = "";
char *lname = NULL, *mname = NULL;
switch_status_t status = SWITCH_STATUS_GENERR;
const char *old_sound_prefix = NULL, *sound_path = NULL, *tts_engine = NULL, *tts_voice = NULL;
const char *module_name = NULL, *chan_lang = NULL;
@ -122,12 +123,15 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s
module_name = chan_lang;
if (!data) {
data = "";
switch_event_create(&hint_data, SWITCH_EVENT_MESSAGE);
switch_assert(hint_data);
switch_event_add_header_string(hint_data, SWITCH_STACK_BOTTOM, "macro_name", macro_name);
switch_event_add_header_string(hint_data, SWITCH_STACK_BOTTOM, "lang", chan_lang);
if (data) {
switch_event_add_header_string(hint_data, SWITCH_STACK_BOTTOM, "data", data);
}
switch_url_encode(data, enc_hint, sizeof(enc_hint));
switch_snprintf(hint_data, sizeof(hint_data), "macro_name=%s&lang=%s&data=%s&destination_number=%s", macro_name, chan_lang, enc_hint, switch_channel_get_variable(channel,"destination_number"));
switch_channel_event_set_data(channel, hint_data);
if (switch_xml_locate("phrases", NULL, NULL, NULL, &xml, &cfg, hint_data) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of phrases failed.\n");
@ -320,6 +324,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s
}
done:
if (hint_data) {
switch_event_destroy(&hint_data);
}
if (!matches) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "macro [%s] did not match any patterns\n", macro_name);
}

View File

@ -1281,7 +1281,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file(const char *file)
SWITCH_DECLARE(switch_status_t) switch_xml_locate(const char *section,
const char *tag_name,
const char *key_name, const char *key_value, switch_xml_t * root, switch_xml_t * node,
const char *params)
switch_event_t *params)
{
switch_xml_t conf = NULL;
switch_xml_t tag = NULL;
@ -1353,17 +1353,24 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate(const char *section,
return SWITCH_STATUS_FALSE;
}
SWITCH_DECLARE(switch_status_t) switch_xml_locate_domain(const char *domain_name, char *params, switch_xml_t *root, switch_xml_t *domain)
SWITCH_DECLARE(switch_status_t) switch_xml_locate_domain(const char *domain_name, switch_event_t *params, switch_xml_t *root, switch_xml_t *domain)
{
char my_params[512];
switch_event_t *my_params = NULL;
switch_status_t status;
*domain = NULL;
if (!params) {
switch_snprintf(my_params, sizeof(my_params), "domain=%s", domain_name);
switch_event_create(&my_params, SWITCH_EVENT_MESSAGE);
switch_assert(my_params);
switch_event_add_header_string(my_params, SWITCH_STACK_BOTTOM, "domain", domain_name);
params = my_params;
}
return switch_xml_locate("directory", "domain", "name", domain_name, root, domain, params);
status = switch_xml_locate("directory", "domain", "name", domain_name, root, domain, params);
if (my_params) {
switch_event_destroy(&my_params);
}
return status;
}
@ -1374,22 +1381,31 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate_user(const char *key,
switch_xml_t *root,
switch_xml_t *domain,
switch_xml_t *user,
const char *xtra_params)
switch_event_t *params)
{
char params[1024] = "";
switch_status_t status;
*root = NULL;
*user = NULL;
*domain = NULL;
if (!switch_strlen_zero(xtra_params)) {
switch_snprintf(params, sizeof(params), "key=%s&user=%s&domain=%s&ip=%s&%s", key,
switch_str_nil(user_name), switch_str_nil(domain_name), switch_str_nil(ip), xtra_params);
} else {
switch_snprintf(params, sizeof(params), "key=%s&user=%s&domain=%s&ip=%s", key,
switch_str_nil(user_name), switch_str_nil(domain_name), switch_str_nil(ip));
xtra_params = "";
if (params) {
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "key", key);
if (user_name) {
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "user", user_name);
}
if (domain_name) {
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "domain", domain_name);
}
if (ip) {
switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "ip", ip);
}
}
if ((status = switch_xml_locate_domain(domain_name, params, root, domain)) != SWITCH_STATUS_SUCCESS) {
return status;
}
@ -1402,7 +1418,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate_user(const char *key,
if (user_name) {
if (!switch_strlen_zero(xtra_params) && strstr(xtra_params, "mailbox")) {
if (params && switch_event_get_header(params, "mailbox")) {
if ((*user = switch_xml_find_child(*domain, "user", "mailbox", user_name))) {
return SWITCH_STATUS_SUCCESS;
}
@ -1507,7 +1523,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_destroy(void)
return SWITCH_STATUS_FALSE;
}
SWITCH_DECLARE(switch_xml_t) switch_xml_open_cfg(const char *file_path, switch_xml_t * node, const char *params)
SWITCH_DECLARE(switch_xml_t) switch_xml_open_cfg(const char *file_path, switch_xml_t *node, switch_event_t *params)
{
switch_xml_t xml = NULL, cfg = NULL;