]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
change xml_lookups to take an event as params instead of url string this will break...
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 23 Jan 2008 20:59:25 +0000 (20:59 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 23 Jan 2008 20:59:25 +0000 (20:59 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7333 d0543943-73ff-0310-b7d9-9358b9ac24b2

16 files changed:
src/include/switch_event.h
src/include/switch_types.h
src/include/switch_xml.h
src/mod/applications/mod_commands/mod_commands.c
src/mod/applications/mod_conference/mod_conference.c
src/mod/applications/mod_dptools/mod_dptools.c
src/mod/applications/mod_voicemail/mod_voicemail.c
src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c
src/mod/endpoints/mod_dingaling/mod_dingaling.c
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_reg.c
src/mod/xml_int/mod_xml_curl/mod_xml_curl.c
src/mod/xml_int/mod_xml_rpc/mod_xml_rpc.c
src/switch_event.c
src/switch_ivr_play_say.c
src/switch_xml.cpp

index b81ed54ac7cdf1acefef64160852cc64659c979c..a2085acf2baf2f64cf1123f5b112365fe033ae52 100644 (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
index ed7c81406291b3620c53e2ac4435767a92d8cbd6..8f4ab6a7155a425119411929664db5101b9eee8e 100644 (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;
index 1c2ce131617ae7ce045c20d6867a80e0584aed22..83413444a280fec7fb5e25d3c4461c264f3d5a8b 100644 (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
index 7b939319790b7a67da6a88642b77097475831278..dbdf0ab9eb5ba8711a2d474338c752d5d725e0df 100644 (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);
index cbf7857240aadf5bdb9175b8a328aa6601003c06..c03823a6c1fca473f8c781e104477a0612864862 100644 (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);
index ec70df73e46b14659eda939280b39da0315e1544..5fa0f7aacbff993a0d45684f3fa37dc67d47d9c2 100644 (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;
index 3ac08b8dcde1c729ad3a75829c01b8b8c7013721..b1ae827c17a4d10c869cbd7564ead5e298de3dc0 100644 (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;
index 31efcec89742a6b5bff9ce2b67d033449ae34e71..d83b465f929b6318911fb1d8f554601844a4c34c 100644 (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;
 }
 
index 37d4dea72afd234c3c1768d757207006176722c3..dcb5ae9f8791d2a365ee4bb45f21a87baf08fce3 100644 (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);
        }
index d4f7055425610b0d74542779b5f39128e21a4646..28ab613fa77a9c5ea4a1cab4c13a74f900363268 100644 (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);
        }
index 61ed6aea88322f768d051d0fc6d6fba59cdcf9fa..06e9abcccd6ef9e5eb13ab146199bf21749f5802 100644 (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);
index cdabf71b1acef247bf9c73347202b4d43c9193be..f1c73d18650f3339f381217a23cc90941f82b77a 100644 (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);
 
index 2c265404af4b720bc990225bbe7726fb79263a32..8249e6844f51b16198943f843f7974a892542728 100644 (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) {
index e72365db1ff444a85f982c8f21ba8b576f65edd4..bc5b3bff4a28df253a96960d328adf722b7933c8 100644 (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
index 1f96862bddbd8c5852d44a76a3baf8a54babd07a..282591410b3fd33b3c6a943b43c13c9745283d5b 100644 (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);
        }
index 61e143a0a410117bd0eeaa97e36d78fcbeab5fe3..484a9e70083d649cd42c7e01ab62d108f3f8e8e6 100644 (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;