From 2eac35df999d0d1645d72bdebbd00df4fad0d9ad Mon Sep 17 00:00:00 2001 From: Anthony Minessale <anthony.minessale@gmail.com> Date: Thu, 11 Jun 2009 17:17:52 +0000 Subject: [PATCH] increase compat on NDLB-to-in-200-contact to handle NAT git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13759 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/endpoints/mod_sofia/sofia.c | 57 ++++++++++++++--------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index c00b8fd723..e5e97709ff 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -4758,7 +4758,8 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ url_set_chanvars(session, sip->sip_to->a_url, sip_to); if (switch_channel_get_variable(channel, "sip_to_uri")) { const char *ipv6; - + const char *url = NULL; + host = switch_channel_get_variable(channel, "sip_to_host"); user = switch_channel_get_variable(channel, "sip_to_user"); @@ -4783,37 +4784,33 @@ void sofia_handle_sip_i_invite(nua_t *nua, sofia_profile_t *profile, nua_handle_ port, sofia_glue_transport2str(transport)); - if (profile->ndlb & PFLAG_NDLB_TO_IN_200_CONTACT) { - if (strchr(tech_pvt->to_uri, '>')) { - tech_pvt->reply_contact = tech_pvt->to_uri; - } else { - tech_pvt->reply_contact = switch_core_session_sprintf(session, "<%s>", tech_pvt->to_uri); - } - } else { - if (sofia_test_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE)) { - tech_pvt->reply_contact = switch_core_session_sprintf(session, "<sip:%s@%s>", user, host); - } else { - const char *url = NULL; - - if (sofia_glue_check_nat(profile, tech_pvt->remote_ip)) { - url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_public_url : profile->public_url; - } else { - url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_url : profile->url; - } - - if (url) { - if (strchr(url, '>')) { - tech_pvt->reply_contact = switch_core_session_sprintf(session, "%s;transport=%s", url, - sofia_glue_transport2str(transport)); - } else { - tech_pvt->reply_contact = switch_core_session_sprintf(session, "<%s;transport=%s>", url, - sofia_glue_transport2str(transport)); - } - } else { - switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); - } + if (sofia_glue_check_nat(profile, tech_pvt->remote_ip)) { + url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_public_url : profile->public_url; + } else { + url = (sofia_glue_transport_has_tls(transport)) ? profile->tls_url : profile->url; + } + + if ((profile->ndlb & PFLAG_NDLB_TO_IN_200_CONTACT) || sofia_test_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE)) { + char *at; + char *tmp = sofia_overcome_sip_uri_weakness(session, url, transport, SWITCH_TRUE, NULL); + if ((at = strchr(tmp, '@'))) { + url = switch_core_session_sprintf(session, "sip:%s%s", user, at); } } + + + if (url) { + if (strchr(url, '>')) { + tech_pvt->reply_contact = switch_core_session_sprintf(session, "%s;transport=%s", url, + sofia_glue_transport2str(transport)); + } else { + tech_pvt->reply_contact = switch_core_session_sprintf(session, "<%s;transport=%s>", url, + sofia_glue_transport2str(transport)); + } + } else { + switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); + } + } else { const char *url = NULL; if (sofia_glue_check_nat(profile, tech_pvt->remote_ip)) {