[Freeswitch-branches] [commit] r13581 - freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia

FreeSWITCH SVN brian at freeswitch.org
Wed Jun 3 12:02:16 PDT 2009


Author: brian
Date: Wed Jun  3 14:02:16 2009
New Revision: 13581

Log:
 refactor and 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_glue.c
   freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.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 14:02:16 2009
@@ -830,7 +830,7 @@
 
 const char *sofia_glue_transport2str(const sofia_transport_t tp);
 char * sofia_glue_find_parameter(const char *str, const char *param);
-
+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);
 switch_status_t sofia_glue_build_crypto(private_object_t *tech_pvt, int index, switch_rtp_crypto_key_type_t type, switch_rtp_crypto_direction_t direction);

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 14:02:16 2009
@@ -665,9 +665,8 @@
 		}
 	}
 
-	if (tech_pvt->remote_ip && sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network && 
-		!switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) {
-		tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, tech_pvt->profile->extrtpip);
+	if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) {
+			tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, tech_pvt->profile->extrtpip);
 		switch_nat_add_mapping((switch_port_t)sdp_port, SWITCH_NAT_UDP);
 	} else {
 		tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, ip);
@@ -716,8 +715,7 @@
 
 	tech_pvt->adv_sdp_video_port = sdp_port;
 
-	if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network && 
-		!switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) {
+	if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) {
 		switch_nat_add_mapping((switch_port_t)sdp_port, SWITCH_NAT_UDP);
 	}
 
@@ -819,6 +817,14 @@
 	}
 }
 
+int sofia_glue_check_nat(sofia_profile_t *profile, const char *network_ip)
+{
+	return (network_ip && 
+			profile->local_network && 
+			sofia_test_pflag(profile, PFLAG_AUTO_NAT) && 
+			!switch_check_network_list_ip(network_ip, profile->local_network));
+}
+
 int sofia_glue_transport_has_tls(const sofia_transport_t tp)
 {
 	switch (tp) {
@@ -1286,9 +1292,8 @@
 		const char* format;
 		const char *alt = NULL;
 
-		if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network) {
-			sipip = (switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) 
-				? tech_pvt->profile->sipip : tech_pvt->profile->extsipip;
+		if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->profile->local_network)) {
+			sipip = tech_pvt->profile->extsipip;
 		} else {
 			sipip = tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : tech_pvt->profile->sipip;
 		}
@@ -1400,8 +1405,7 @@
 			}
 		}
 		
-		if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network && 
-			!switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) {
+		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);
@@ -1419,7 +1423,7 @@
 				char *ip_addr;
 				char *ipv6;
 				
-				if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network) {
+				if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) { 
 					ip_addr = (switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) 
 						? tech_pvt->profile->sipip : tech_pvt->profile->extsipip;
 				} else {
@@ -1440,8 +1444,7 @@
 				if (sofia_glue_transport_has_tls(tech_pvt->transport)) {
 					tech_pvt->invite_contact = tech_pvt->profile->tls_url;
 				} else {
-					if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network && 
-						!switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) {
+					if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) { 
 						tech_pvt->invite_contact = tech_pvt->profile->public_url;
 					} else {
 						tech_pvt->invite_contact = tech_pvt->profile->url;
@@ -1694,9 +1697,8 @@
 	switch_mutex_lock(tech_pvt->sofia_mutex);
 	caller_profile = switch_channel_get_caller_profile(channel);
 
-	if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network) {
-		sipip = (switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) 
-			? tech_pvt->profile->sipip : tech_pvt->profile->extsipip;
+	if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) { 
+		sipip = tech_pvt->profile->extsipip;
 		contact_url = tech_pvt->profile->public_url;
 	} else {
 		sipip = tech_pvt->profile->extsipip ? tech_pvt->profile->extsipip : tech_pvt->profile->sipip;
@@ -1831,8 +1833,7 @@
 		switch_rtp_release_port(tech_pvt->profile->rtpip, tech_pvt->local_sdp_audio_port);
 	}
 
-	if (tech_pvt->local_sdp_audio_port > 0 && sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network &&
-		!switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) {
+	if (tech_pvt->local_sdp_audio_port > 0 && sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) { 
 		switch_nat_del_mapping((switch_port_t)tech_pvt->local_sdp_audio_port, SWITCH_NAT_UDP);
 	}
 	
@@ -1842,8 +1843,8 @@
 		switch_rtp_release_port(tech_pvt->profile->rtpip, tech_pvt->local_sdp_video_port);
 	}
 
-	if (tech_pvt->local_sdp_video_port > 0 && sofia_test_pflag(tech_pvt->profile, PFLAG_AUTO_NAT) && tech_pvt->profile->local_network &&
-		!switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) {
+		
+	if (tech_pvt->local_sdp_video_port > 0 && sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) { 
 		switch_nat_del_mapping((switch_port_t)tech_pvt->local_sdp_video_port, SWITCH_NAT_UDP);
 	}
 }

Modified: freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c
==============================================================================
--- freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c	(original)
+++ freeswitch/branches/brian/trunk/src/mod/endpoints/mod_sofia/sofia_sla.c	Wed Jun  3 14:02:16 2009
@@ -103,7 +103,7 @@
 	nua_handle_bind(nh, &mod_sofia_globals.keep_private);
 
 	switch_snprintf(exp_str, sizeof(exp_str), "%ld", exptime + 30);
-	if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(network_ip, profile->local_network)) {
+	if (sofia_glue_check_nat(profile, network_ip)) { 
 		switch_snprintf(my_contact, sizeof(my_contact), "<sip:%s@%s;transport=%s>;expires=%s", profile->sla_contact, 
 						profile->extsipip, sofia_glue_transport2str(transport), exp_str);
 	} else {
@@ -200,11 +200,10 @@
 			*p++ = '\0';
 		}
 	}
-	
-	if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(network_ip, profile->local_network)) {
+	if (sofia_glue_check_nat(profile, network_ip)) { 
 		sla_contact = switch_mprintf("<sip:%s@%s;transport=%s>", profile->sla_contact, profile->extsipip, sofia_glue_transport2str(transport));
 	} else {
-		sla_contact = switch_mprintf("<sip:%s@%s;transport=%s>", profile->sla_contact, profile->extsipip, sofia_glue_transport2str(transport));
+		sla_contact = switch_mprintf("<sip:%s@%s;transport=%s>", profile->sla_contact, profile->sipip, sofia_glue_transport2str(transport));
 	}
 
 	nua_respond(nh, SIP_202_ACCEPTED, SIPTAG_CONTACT_STR(sla_contact), NUTAG_WITH_THIS(nua),
@@ -337,6 +336,7 @@
 	nua_handle_t *nh;
 	char *route_uri = NULL;
 	char *xml_fixup = NULL;
+	char *fixup = NULL;
 	nh = nua_handle_by_call_id(helper->profile->nua, call_id);  /* that's all you need to find the subscription's nh */
 
 	if (nh) {
@@ -359,11 +359,14 @@
 				*p++ = '\0';
 			}
 		}
-		
-		if (sofia_test_pflag(helper->profile, PFLAG_AUTO_NAT) && !switch_check_network_list_ip(network_ip, helper->profile->local_network)) {
-			xml_fixup = switch_string_replace(helper->payload, helper->profile->sipip, helper->profile->extsipip);
-		} else if (sofia_test_pflag(helper->profile, PFLAG_AUTO_NAT) && switch_check_network_list_ip(network_ip, helper->profile->local_network)) {
-			xml_fixup = switch_string_replace(helper->payload, helper->profile->extsipip, helper->profile->sipip);
+
+		if (sofia_test_pflag(helper->profile, PFLAG_AUTO_NAT)) {
+			if (sofia_glue_check_nat(helper->profile, network_ip)) { 
+				fixup = switch_string_replace(helper->payload, helper->profile->sipip, helper->profile->extsipip);
+			} else  {
+				fixup = switch_string_replace(helper->payload, helper->profile->extsipip, helper->profile->sipip);
+			}
+			xml_fixup = fixup;
 		} else {
 			xml_fixup = helper->payload;
 		}
@@ -375,7 +378,7 @@
 				   SIPTAG_PAYLOAD_STR(xml_fixup),
 				   TAG_END());
 		switch_safe_free(route_uri);
-		switch_safe_free(xml_fixup);
+		switch_safe_free(fixup);
 	}
 	return 0;
 }



More information about the Freeswitch-branches mailing list