]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-5498
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 19 Jul 2013 17:03:46 +0000 (12:03 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Fri, 19 Jul 2013 17:03:51 +0000 (12:03 -0500)
src/include/switch_ivr.h
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_presence.c
src/mod/endpoints/mod_sofia/sofia_reg.c
src/switch_ivr.c
src/switch_xml.c

index ba5ad7011bd88d080e8a601ef919257b45011d32..7a8d9e66030795d326394a3294d613b2e0fc8e33 100644 (file)
@@ -934,6 +934,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_say_ip(switch_core_session_t *session
                                                                                                  switch_input_args_t *args);
 
 SWITCH_DECLARE(switch_status_t) switch_ivr_set_user(switch_core_session_t *session, const char *data);
+SWITCH_DECLARE(switch_status_t) switch_ivr_set_user_xml(switch_core_session_t *session, const char *prefix,
+                                                                                                               const char *user, const char *domain, switch_xml_t x_user);
+
 SWITCH_DECLARE(switch_status_t) switch_ivr_sound_test(switch_core_session_t *session);
 SWITCH_DECLARE(void) switch_process_import(switch_core_session_t *session, switch_channel_t *peer_channel, const char *varname, const char *prefix);
 SWITCH_DECLARE(switch_bool_t) switch_ivr_uuid_exists(const char *uuid);
index ac8b4366f797ec1a7a866c94724127a55ef02d19..574e211209efb62c0c10bf6e4e671f364f59dbfc 100644 (file)
@@ -888,7 +888,7 @@ void sofia_reg_auth_challenge(sofia_profile_t *profile, nua_handle_t *nh, sofia_
 auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, sip_authorization_t const *authorization,
                                                                sip_t const *sip,
                                                                sofia_dispatch_event_t *de, const char *regstr, char *np, size_t nplen, char *ip, switch_event_t **v_event,
-                                                               long exptime, sofia_regtype_t regtype, const char *to_user, switch_event_t **auth_params, long *reg_count);
+                                                               long exptime, sofia_regtype_t regtype, const char *to_user, switch_event_t **auth_params, long *reg_count, switch_xml_t *user_xml);
 
 
 void sofia_reg_handle_sip_r_challenge(int status,
@@ -935,7 +935,7 @@ void sofia_glue_do_xfer_invite(switch_core_session_t *session);
 uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sip_t const *sip,
                                                                  sofia_dispatch_event_t *de,
                                                                  sofia_regtype_t regtype, char *key, 
-                                                                 uint32_t keylen, switch_event_t **v_event, const char *is_nat, sofia_private_t **sofia_private_p);
+                                                                 uint32_t keylen, switch_event_t **v_event, const char *is_nat, sofia_private_t **sofia_private_p, switch_xml_t *user_xml);
 extern switch_endpoint_interface_t *sofia_endpoint_interface;
 void sofia_presence_set_chat_hash(private_object_t *tech_pvt, sip_t const *sip);
 switch_status_t sofia_on_hangup(switch_core_session_t *session);
index 102840292931ce1277fe8adbf7f5de0387d40102..33579e8b00338acd88de4d856c0634a59ddc449b 100644 (file)
@@ -1108,7 +1108,7 @@ static void our_sofia_event_callback(nua_event_t event,
                        sofia_glue_get_addr(de->data->e_msg, network_ip, sizeof(network_ip), NULL);
                        auth_res = sofia_reg_parse_auth(profile, authorization, sip, de,
                                                                                        (char *) sip->sip_request->rq_method_name, tech_pvt->key, strlen(tech_pvt->key), network_ip, NULL, 0,
-                                                                                       REG_INVITE, NULL, NULL, NULL);
+                                                                                       REG_INVITE, NULL, NULL, NULL, NULL);
                }
 
                if ((auth_res != AUTH_OK && auth_res != AUTH_RENEWED)) {
@@ -7763,6 +7763,7 @@ void sofia_handle_sip_i_invite(switch_core_session_t *session, nua_t *nua, sofia
        char network_ip[80];
        char proxied_client_ip[80];
        switch_event_t *v_event = NULL;
+       switch_xml_t x_user = NULL;
        uint32_t sess_count = switch_core_session_count();
        uint32_t sess_max = switch_core_session_limit(0);
        int is_auth = 0, calling_myself = 0;
@@ -8000,10 +8001,13 @@ void sofia_handle_sip_i_invite(switch_core_session_t *session, nua_t *nua, sofia
                if (!strcmp(network_ip, profile->sipip) && network_port == profile->sip_port) {
                        calling_myself++;
                } else {
-                       if (sofia_reg_handle_register(nua, profile, nh, sip, de, REG_INVITE, key, sizeof(key), &v_event, NULL, NULL)) {
+                       if (sofia_reg_handle_register(nua, profile, nh, sip, de, REG_INVITE, key, sizeof(key), &v_event, NULL, NULL, &x_user)) {
                                if (v_event) {
                                        switch_event_destroy(&v_event);
                                }
+                               if (x_user) {
+                                       switch_xml_free(x_user);
+                               }
 
                                if (sip->sip_authorization || sip->sip_proxy_authorization) {
                                        goto fail;
@@ -8086,15 +8090,6 @@ void sofia_handle_sip_i_invite(switch_core_session_t *session, nua_t *nua, sofia
                switch_channel_set_variable(channel, "sip_looped_call", "true");
        }
 
-       if (v_event) {
-               switch_event_header_t *hp;
-
-               for (hp = v_event->headers; hp; hp = hp->next) {
-                       switch_channel_set_variable(channel, hp->name, hp->value);
-               }
-               switch_event_destroy(&v_event);
-       }
-
        if (sip->sip_from && sip->sip_from->a_url) {
                from_user = sip->sip_from->a_url->url_user;
                from_host = sip->sip_from->a_url->url_host;
@@ -8841,6 +8836,25 @@ void sofia_handle_sip_i_invite(switch_core_session_t *session, nua_t *nua, sofia
                switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
        }
 
+       if (x_user) {
+               const char *user = NULL, *domain = NULL;
+
+               if (v_event) {
+                       user = switch_event_get_header(v_event, "username");
+                       domain = switch_event_get_header(v_event, "domain_name");
+               }
+
+               printf("W00t!!!!\n");
+               switch_ivr_set_user_xml(session, NULL, user, domain, x_user);
+               switch_xml_free(x_user);
+               x_user = NULL;
+       }
+
+       if (v_event) {
+               switch_event_destroy(&v_event);
+       }
+
+
        tech_pvt->sofia_private = sofia_private;
        tech_pvt->nh = nh;
 
index 8ac0629ae1db2360af1172f15bba636462957123..cadd52d513652fb927714265fd87a3d85dcb5a67 100644 (file)
@@ -4475,8 +4475,8 @@ void sofia_presence_handle_sip_i_message(int status,
                                sofia_glue_get_addr(de->data->e_msg, network_ip, sizeof(network_ip), NULL);
                                auth_res = sofia_reg_parse_auth(profile, authorization, sip, de,
                                                                                                (char *) sip->sip_request->rq_method_name, key, keylen, network_ip, NULL, 0,
-                                                                                               REG_INVITE, NULL, NULL, NULL);
-                       } else if ( sofia_reg_handle_register(nua, profile, nh, sip, de, REG_INVITE, key, keylen, &v_event, NULL, NULL)) {
+                                                                                               REG_INVITE, NULL, NULL, NULL, NULL);
+                       } else if ( sofia_reg_handle_register(nua, profile, nh, sip, de, REG_INVITE, key, keylen, &v_event, NULL, NULL, NULL)) {
                                if (v_event) {
                                        switch_event_destroy(&v_event);
                                }
index d45896a1a7c342f069fbad3dd5399393f57553d9..23f211f53fdb4f6b791d3a75a09e419d18a50bbc 100644 (file)
@@ -1121,7 +1121,7 @@ void sofia_reg_close_handles(sofia_profile_t *profile)
 
 uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sip_t const *sip,
                                                                sofia_dispatch_event_t *de, sofia_regtype_t regtype, char *key,
-                                                                 uint32_t keylen, switch_event_t **v_event, const char *is_nat, sofia_private_t **sofia_private_p)
+                                                                 uint32_t keylen, switch_event_t **v_event, const char *is_nat, sofia_private_t **sofia_private_p, switch_xml_t *user_xml)
 {
        sip_to_t const *to = NULL;
        sip_from_t const *from = NULL;
@@ -1399,7 +1399,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
                const char *username = "unknown";
                const char *realm = reg_host;
                if ((auth_res = sofia_reg_parse_auth(profile, authorization, sip, de, sip->sip_request->rq_method_name,
-                                                                                        key, keylen, network_ip, v_event, exptime, regtype, to_user, &auth_params, &reg_count)) == AUTH_STALE) {
+                                                                                        key, keylen, network_ip, v_event, exptime, regtype, to_user, &auth_params, &reg_count, user_xml)) == AUTH_STALE) {
                        stale = 1;
                }
 
@@ -2160,7 +2160,7 @@ void sofia_reg_handle_sip_i_register(nua_t *nua, sofia_profile_t *profile, nua_h
                is_nat = NULL;
        }
 
-       sofia_reg_handle_register(nua, profile, nh, sip, de, type, key, sizeof(key), &v_event, is_nat, sofia_private_p);
+       sofia_reg_handle_register(nua, profile, nh, sip, de, type, key, sizeof(key), &v_event, is_nat, sofia_private_p, NULL);
 
        if (v_event) {
                switch_event_destroy(&v_event);
@@ -2467,7 +2467,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile,
                                                                size_t nplen,
                                                                char *ip,
                                                                switch_event_t **v_event,
-                                                               long exptime, sofia_regtype_t regtype, const char *to_user, switch_event_t **auth_params, long *reg_count)
+                                                               long exptime, sofia_regtype_t regtype, const char *to_user, switch_event_t **auth_params, long *reg_count, switch_xml_t *user_xml)
 {
        int indexnum;
        const char *cur;
@@ -2891,7 +2891,7 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile,
 
   skip_auth:
        if (first && (ret == AUTH_OK || ret == AUTH_RENEWED)) {
-               if (v_event) {
+               if (!v_event) {
                        switch_event_create_plain(v_event, SWITCH_EVENT_REQUEST_PARAMS);
                }
 
@@ -3023,7 +3023,11 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile,
        switch_event_destroy(&params);
 
        if (user) {
-               switch_xml_free(user);
+               if (user_xml) {
+                       *user_xml = user;
+               } else {
+                       switch_xml_free(user);
+               }
        }
 
        switch_safe_free(input);
index e98be1349e1689738612113aba76675ae0e93c31..c3dc715e759663ee32a86aca0362000d52418e0a 100644 (file)
@@ -3190,36 +3190,18 @@ static const char *get_prefixed_str(char *buffer, size_t buffer_size, const char
        return buffer;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_ivr_set_user(switch_core_session_t *session, const char *data)
+SWITCH_DECLARE(switch_status_t) switch_ivr_set_user_xml(switch_core_session_t *session, const char *prefix, 
+                                                                                                               const char *user, const char *domain, switch_xml_t x_user)
 {
-       switch_xml_t x_domain, xml = NULL, x_user, x_param, x_params, x_group = NULL;
-       char *user, *number_alias, *domain;
+       switch_xml_t x_params, x_param;
+       char *number_alias;
        switch_channel_t *channel = switch_core_session_get_channel(session);
        switch_status_t status = SWITCH_STATUS_FALSE;
 
-       char *prefix_buffer = NULL, *prefix;
+       char *prefix_buffer = NULL;
        size_t buffer_size = 0;
        size_t prefix_size = 0;
-       if (zstr(data)) {
-               goto error;
-       }
-
-       user = switch_core_session_strdup(session, data);
-
-       if ((prefix = strchr(user, ' '))) {
-               *prefix++ = 0;
-       }
 
-       if (!(domain = strchr(user, '@'))) {
-               goto error;
-       }
-
-       *domain++ = '\0';
-
-       if (switch_xml_locate_user("id", user, domain, NULL, &xml, &x_domain, &x_user, &x_group, NULL) != SWITCH_STATUS_SUCCESS) {
-               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", user, domain);
-               goto done;
-       }
 
        status = SWITCH_STATUS_SUCCESS;
 
@@ -3233,7 +3215,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_set_user(switch_core_session_t *sessi
                switch_channel_set_variable(channel, get_prefixed_str(prefix_buffer, buffer_size, prefix, prefix_size, "number_alias"), number_alias);
        }
 
-       if ((x_params = switch_xml_child(x_domain, "variables"))) {
+       if ((x_params = switch_xml_child(x_user, "variables"))) {
                for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) {
                        const char *var = switch_xml_attr(x_param, "name");
                        const char *val = switch_xml_attr(x_param, "value");
@@ -3244,7 +3226,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_set_user(switch_core_session_t *sessi
                }
        }
 
-       if ((x_params = switch_xml_child(x_domain, "profile-variables"))) {
+       if ((x_params = switch_xml_child(x_user, "profile-variables"))) {
                for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) {
                        const char *var = switch_xml_attr(x_param, "name");
                        const char *val = switch_xml_attr(x_param, "value");
@@ -3255,61 +3237,55 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_set_user(switch_core_session_t *sessi
                }
        }
 
-       if (x_group && (x_params = switch_xml_child(x_group, "variables"))) {
-               for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) {
-                       const char *var = switch_xml_attr(x_param, "name");
-                       const char *val = switch_xml_attr(x_param, "value");
-
-                       if (var && val) {
-                               switch_channel_set_variable(channel, get_prefixed_str(prefix_buffer, buffer_size, prefix, prefix_size, var), val);
-                       }
-               }
+       if (user && domain) {
+               switch_channel_set_variable(channel, get_prefixed_str(prefix_buffer, buffer_size, prefix, prefix_size, "user_name"), user);
+               switch_channel_set_variable(channel, get_prefixed_str(prefix_buffer, buffer_size, prefix, prefix_size, "domain_name"), domain);
        }
 
-       if ((x_params = switch_xml_child(x_group, "profile-variables"))) {
-               for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) {
-                       const char *var = switch_xml_attr(x_param, "name");
-                       const char *val = switch_xml_attr(x_param, "value");
+       return status;
+}
 
-                       if (var && val) {
-                               switch_channel_set_profile_var(channel, get_prefixed_str(prefix_buffer, buffer_size, prefix, prefix_size, var), val);
-                       }
-               }
-       }
+SWITCH_DECLARE(switch_status_t) switch_ivr_set_user(switch_core_session_t *session, const char *data)
+{
+       switch_xml_t x_user;
+       char *user, *domain;
+       switch_status_t status = SWITCH_STATUS_FALSE;
 
-       if ((x_params = switch_xml_child(x_user, "variables"))) {
-               for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) {
-                       const char *var = switch_xml_attr(x_param, "name");
-                       const char *val = switch_xml_attr(x_param, "value");
+       char *prefix;
 
-                       if (var && val) {
-                               switch_channel_set_variable(channel, get_prefixed_str(prefix_buffer, buffer_size, prefix, prefix_size, var), val);
-                       }
-               }
+       if (zstr(data)) {
+               goto error;
        }
 
-       if ((x_params = switch_xml_child(x_user, "profile-variables"))) {
-               for (x_param = switch_xml_child(x_params, "variable"); x_param; x_param = x_param->next) {
-                       const char *var = switch_xml_attr(x_param, "name");
-                       const char *val = switch_xml_attr(x_param, "value");
+       user = switch_core_session_strdup(session, data);
 
-                       if (var && val) {
-                               switch_channel_set_profile_var(channel, get_prefixed_str(prefix_buffer, buffer_size, prefix, prefix_size, var), val);
-                       }
-               }
+       if ((prefix = strchr(user, ' '))) {
+               *prefix++ = 0;
        }
 
-       switch_channel_set_variable(channel, get_prefixed_str(prefix_buffer, buffer_size, prefix, prefix_size, "user_name"), user);
-       switch_channel_set_variable(channel, get_prefixed_str(prefix_buffer, buffer_size, prefix, prefix_size, "domain_name"), domain);
+       if (!(domain = strchr(user, '@'))) {
+               goto error;
+       }
+
+       *domain++ = '\0';
 
+
+       if (switch_xml_locate_user_merged("id", user, domain, NULL, &x_user, NULL) != SWITCH_STATUS_SUCCESS) {
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", user, domain);
+               goto done;
+       }
+
+       status = switch_ivr_set_user_xml(session, prefix, user, domain, x_user);
+       
        goto done;
 
   error:
        switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No user@domain specified.\n");
 
   done:
-       if (xml) {
-               switch_xml_free(xml);
+
+       if (x_user) {
+               switch_xml_free(x_user);
        }
 
        return status;
index c13e33bea473563de3a129445847182253b28cfb..369f88e2c1975f5666c8fc6d21fcbbade9881d81 100644 (file)
@@ -1919,8 +1919,10 @@ SWITCH_DECLARE(void) switch_xml_merge_user(switch_xml_t user, switch_xml_t domai
 
        do_merge(user, group, "params", "param");
        do_merge(user, group, "variables", "variable");
+       do_merge(user, group, "profile-variables", "variable");
        do_merge(user, domain, "params", "param");
        do_merge(user, domain, "variables", "variable");
+       do_merge(user, domain, "profile-variables", "variable");
 }
 
 SWITCH_DECLARE(uint32_t) switch_xml_clear_user_cache(const char *key, const char *user_name, const char *domain_name)