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
@@ -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);
@@ -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);
+22 -12
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;
@@ -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;
@@ -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;
}
@@ -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);
}
+10 -4
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);
}
+12 -6
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);
+14 -10
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);
+9 -2
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) {