[Freeswitch-branches] [commit] r13592 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia
FreeSWITCH SVN
brian at freeswitch.org
Wed Jun 3 13:49:57 PDT 2009
Author: brian
Date: Wed Jun 3 15:49:57 2009
New Revision: 13592
Log:
more clean up
Modified:
freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c
freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c
freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
==============================================================================
--- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (original)
+++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h Wed Jun 3 15:49:57 2009
@@ -436,8 +436,8 @@
sofia_cid_type_t cid_type;
sofia_dtmf_t dtmf_type;
int auto_restart;
- int sip_port;
- int tls_sip_port;
+ switch_port_t sip_port;
+ switch_port_t tls_sip_port;
int tls_version;
char *codec_string;
int running;
@@ -830,6 +830,8 @@
const char *sofia_glue_transport2str(const sofia_transport_t tp);
char * sofia_glue_find_parameter(const char *str, const char *param);
+char *sofia_glue_create_via(switch_core_session_t *session, const char *ip, switch_port_t port, sofia_transport_t transport);
+char *sofia_glue_create_external_via(switch_core_session_t *session, sofia_profile_t *profile, sofia_transport_t transport);
int sofia_glue_check_nat(sofia_profile_t *profile, const char *network_ip);
int sofia_glue_transport_has_tls(const sofia_transport_t tp);
const char *sofia_glue_get_unknown_header(sip_t const *sip, const char *name);
Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c (original)
+++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia.c Wed Jun 3 15:49:57 2009
@@ -762,13 +762,13 @@
);
if (sofia_test_pflag(profile, PFLAG_AUTO_NAT)) {
- if (switch_nat_add_mapping((switch_port_t)profile->sip_port, SWITCH_NAT_UDP) == SWITCH_STATUS_SUCCESS) {
+ if (switch_nat_add_mapping(profile->sip_port, SWITCH_NAT_UDP) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created UDP nat mapping for %s port %d\n", profile->name, profile->sip_port);
}
- if (switch_nat_add_mapping((switch_port_t)profile->sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) {
+ if (switch_nat_add_mapping(profile->sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created TCP nat mapping for %s port %d\n", profile->name, profile->sip_port);
}
- if(profile->tls_sip_port && switch_nat_add_mapping((switch_port_t)profile->tls_sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) {
+ if(sofia_test_pflag(profile, PFLAG_TLS) && switch_nat_add_mapping(profile->tls_sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created TCP/TLS nat mapping for %s port %d\n", profile->name, profile->tls_sip_port);
}
}
@@ -953,13 +953,13 @@
}
if (sofia_test_pflag(profile, PFLAG_AUTO_NAT)) {
- if (switch_nat_del_mapping((switch_port_t)profile->sip_port, SWITCH_NAT_UDP) == SWITCH_STATUS_SUCCESS) {
+ if (switch_nat_del_mapping(profile->sip_port, SWITCH_NAT_UDP) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleted UDP nat mapping for %s port %d\n", profile->name, profile->sip_port);
}
- if (switch_nat_del_mapping((switch_port_t)profile->sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) {
+ if (switch_nat_del_mapping(profile->sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleted TCP nat mapping for %s port %d\n", profile->name, profile->sip_port);
}
- if(profile->tls_sip_port && switch_nat_del_mapping((switch_port_t)profile->tls_sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) {
+ if(sofia_test_pflag(profile, PFLAG_TLS) && switch_nat_del_mapping(profile->tls_sip_port, SWITCH_NAT_TCP) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleted TCP/TLS nat mapping for %s port %d\n", profile->name, profile->tls_sip_port);
}
}
@@ -4347,6 +4347,7 @@
int network_port = 0;
char *is_nat = NULL;
char acl_token[512] = "";
+ sofia_transport_t transport;
profile->ib_calls++;
@@ -4488,11 +4489,6 @@
tech_pvt->remote_ip = switch_core_session_strdup(session, network_ip);
tech_pvt->remote_port = network_port;
- if (sofia_glue_check_nat(profile, tech_pvt->remote_ip)) {
- tech_pvt->user_via = switch_core_session_sprintf(session, "SIP/2.0/%s %s;rport",
- sofia_glue_transport2str(sofia_glue_url2transport(sip->sip_contact->m_url)),
- profile->extsipip);
- }
channel = tech_pvt->channel = switch_core_session_get_channel(session);
@@ -4509,7 +4505,7 @@
if (sip->sip_contact && sip->sip_contact->m_url) {
char tmp[35] = "";
- sofia_transport_t transport = sofia_glue_url2transport(sip->sip_contact->m_url);
+ transport = sofia_glue_url2transport(sip->sip_contact->m_url);
const char *ipv6 = strchr(tech_pvt->remote_ip, ':');
tech_pvt->record_route =
@@ -4638,7 +4634,6 @@
if (sip->sip_to && sip->sip_to->a_url) {
const char *host, *user;
int port;
- sofia_transport_t transport;
url_t *transport_url;
if (sip->sip_record_route && sip->sip_record_route->r_url) {
@@ -4731,6 +4726,10 @@
}
}
+ if (sofia_glue_check_nat(profile, tech_pvt->remote_ip)) {
+ tech_pvt->user_via = sofia_glue_create_external_via(session, profile, tech_pvt->transport);
+ }
+
if (sip->sip_contact && sip->sip_contact->m_url) {
const char *contact_uri = url_set_chanvars(session, sip->sip_contact->m_url, sip_contact);
if (!channel_name) {
Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
==============================================================================
--- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (original)
+++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Wed Jun 3 15:49:57 2009
@@ -817,6 +817,32 @@
}
}
+char *sofia_glue_create_external_via(switch_core_session_t *session, sofia_profile_t *profile, sofia_transport_t transport)
+{
+ return sofia_glue_create_via(session,
+ profile->extsipip,
+ (sofia_glue_transport_has_tls(transport))
+ ? profile->tls_sip_port : profile->sip_port,
+ transport);
+}
+
+char *sofia_glue_create_via(switch_core_session_t *session, const char *ip, switch_port_t port, sofia_transport_t transport)
+{
+ if (port && port != 5060) {
+ if (session) {
+ return switch_core_session_sprintf(session, "SIP/2.0/%s %s:%d;rport", sofia_glue_transport2str(transport), ip, port);
+ } else {
+ return switch_mprintf("SIP/2.0/%s %s:%d;rport", sofia_glue_transport2str(transport), ip, port);
+ }
+ } else {
+ if (session) {
+ return switch_core_session_sprintf(session, "SIP/2.0/%s %s;rport", sofia_glue_transport2str(transport), ip);
+ } else {
+ return switch_mprintf("SIP/2.0/%s %s;rport", sofia_glue_transport2str(transport), ip);
+ }
+ }
+}
+
int sofia_glue_check_nat(sofia_profile_t *profile, const char *network_ip)
{
return (network_ip &&
@@ -1406,9 +1432,7 @@
}
if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) {
- const char *transport = sofia_glue_transport2str(tech_pvt->transport);
- tech_pvt->user_via = switch_core_session_sprintf(session, "SIP/2.0/%s %s;rport",
- transport, tech_pvt->profile->extsipip);
+ tech_pvt->user_via = sofia_glue_create_external_via(session, tech_pvt->profile, tech_pvt->transport);
}
Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c
==============================================================================
--- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c (original)
+++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c Wed Jun 3 15:49:57 2009
@@ -1441,11 +1441,9 @@
contact_str = profile->public_url;
break;
}
-
- user_via = switch_mprintf("SIP/2.0/%s %s;rport", transport_str, profile->extsipip);
-
+ user_via = sofia_glue_create_external_via(NULL, profile, transport);
} else {
- user_via = switch_mprintf("SIP/2.0/UDP %s;rport", profile->extsipip);
+ user_via = sofia_glue_create_external_via(NULL, profile, SOFIA_TRANSPORT_UDP);
contact_str = profile->public_url;
}
Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
==============================================================================
--- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (original)
+++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c Wed Jun 3 15:49:57 2009
@@ -444,10 +444,9 @@
break;
}
- user_via = switch_mprintf("SIP/2.0/%s %s;rport", transport_str, profile->extsipip);
-
+ user_via = sofia_glue_create_external_via(NULL, profile, transport);
} else {
- user_via = switch_mprintf("SIP/2.0/UDP %s;rport", profile->extsipip);
+ user_via = sofia_glue_create_external_via(NULL, profile, SOFIA_TRANSPORT_UDP);
contact_str = profile->public_url;
}
More information about the Freeswitch-branches
mailing list