[Freeswitch-svn] [commit] r6688 - freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_sofia

Freeswitch SVN stkn at freeswitch.org
Tue Dec 11 19:47:25 EST 2007


Author: stkn
Date: Tue Dec 11 19:47:25 2007
New Revision: 6688

Modified:
   freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
   freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_sofia/sofia.c
   freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c

Log:
Still not working...

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	Tue Dec 11 19:47:25 2007
@@ -328,6 +328,8 @@
 		}
 	}
 
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Answering channel with reply_contact: %s\n", tech_pvt->reply_contact);
+
 	nua_respond(tech_pvt->nh, SIP_200_OK,
 				NUTAG_SESSION_TIMER(session_timeout),
 				SIPTAG_CONTACT_STR(tech_pvt->reply_contact),

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	Tue Dec 11 19:47:25 2007
@@ -220,6 +220,7 @@
 	char *username;
 	char *url;
 	char *bindurl;
+	char *tls_url;
 	char *tls_bindurl;
 	char *sipdomain;
 	char *timer_name;
@@ -533,4 +534,13 @@
 																		\
 		if(_session) break;												\
 	} while(!_session)
-	   
+
+
+/*
+ * Transport handling helper functions
+ */
+sofia_transport_t sofia_glue_via2transport(const sip_via_t *via);
+sofia_transport_t sofia_glue_url2transport(const url_t *url);
+
+const char *sofia_glue_transport2str(const sofia_transport_t tp);
+const char *sofia_glue_transport2scheme(const sofia_transport_t tp);

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_sofia/sofia.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_sofia/sofia.c	Tue Dec 11 19:47:25 2007
@@ -1062,8 +1062,10 @@
 					}
 
 					if (profile->extsipip) {
+						profile->tls_url = switch_core_sprintf(profile->pool, "sips:mod_sofia@%s:%d", profile->extsipip, profile->tls_sip_port);
 						profile->tls_bindurl = switch_core_sprintf(profile->pool, "sips:mod_sofia@%s:%d;maddr=%s", profile->extsipip, profile->tls_sip_port, profile->sipip);
 					} else {
+						profile->tls_url = switch_core_sprintf(profile->pool, "sips:mod_sofia@%s:%d", profile->extsipip, profile->tls_sip_port);
 						profile->tls_bindurl = switch_core_sprintf(profile->pool, "sips:mod_sofia@%s:%d", profile->sipip, profile->tls_sip_port);
 					}
 
@@ -2009,11 +2011,12 @@
 
 	if (sip->sip_to && sip->sip_to->a_url) {
 		const char *val;
-		char *transport = (my_addrinfo->ai_socktype == SOCK_STREAM) ? "tcp" : "udp";
-		
+		sofia_transport_t transport = sofia_glue_url2transport(sip->sip_contact->m_url);
+
 		url_set_chanvars(session, sip->sip_to->a_url, sip_to);
 		if ((val = switch_channel_get_variable(channel, "sip_to_uri"))) {
-			tech_pvt->to_uri = switch_core_session_sprintf(session, "sip:%s;transport=%s", val, transport);
+
+			tech_pvt->to_uri = switch_core_session_sprintf(session, "%s:%s;transport=%s", sofia_glue_transport2scheme(transport), val, 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;
@@ -2022,18 +2025,20 @@
 				}
 			} else {
 				if (strchr(profile->url, '>')) {
-					tech_pvt->reply_contact = switch_core_session_sprintf(session, "%s;transport=%s", profile->url, transport);
+					tech_pvt->reply_contact = switch_core_session_sprintf(session, "%s;transport=%s", profile->url, sofia_glue_transport2str(transport));
 				} else {
-					tech_pvt->reply_contact = switch_core_session_sprintf(session, "<%s;transport=%s>", profile->url, transport);
+					tech_pvt->reply_contact = switch_core_session_sprintf(session, "<%s;transport=%s>", profile->url, sofia_glue_transport2str(transport));
 				}
 			}
 		} else {
 			if (strchr(profile->url, '>')) {
-				tech_pvt->reply_contact = switch_core_session_sprintf(session, "%s;transport=%s", profile->url, transport);
+				tech_pvt->reply_contact = switch_core_session_sprintf(session, "%s;transport=%s", profile->url, sofia_glue_transport2str(transport));
 			} else {
-				tech_pvt->reply_contact = switch_core_session_sprintf(session, "<%s;transport=%s>", profile->url, transport);
+				tech_pvt->reply_contact = switch_core_session_sprintf(session, "<%s;transport=%s>", profile->url, sofia_glue_transport2str(transport));
 			}
 		}
+
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Resulting Reply-Contact: %s\n", tech_pvt->reply_contact);
 	}
 
 	if (sip->sip_contact && sip->sip_contact->m_url) {

Modified: freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
==============================================================================
--- freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	(original)
+++ freeswitch/branches/stkn/sofia-exp/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	Tue Dec 11 19:47:25 2007
@@ -471,7 +471,121 @@
 	return SOFIA_TRANSPORT_UNKNOWN;
 }
 
-static const char *sofia_glue_transport2str(const sofia_transport_t tp)
+sofia_transport_t sofia_glue_url2transport(const url_t *url)
+{
+	char *ptr = NULL;
+	int tls = 0;
+
+	if(!url)
+		return SOFIA_TRANSPORT_UNKNOWN;
+
+	if (url->url_scheme && !strcasecmp(url->url_scheme, "sips")) {
+		tls++;
+	}
+
+	ptr = (char *)url->url_params;
+	while(ptr) {
+
+		if (!strncasecmp(ptr, "transport", 9)) {
+			ptr += 10;
+
+			if (!strncasecmp(ptr, "udp", 3)) {
+				return SOFIA_TRANSPORT_UDP;
+			}
+			else if (!strncasecmp(ptr, "tcp", 3)) {
+				return SOFIA_TRANSPORT_TCP;
+			}
+			else if (!strncasecmp(ptr, "tls", 3)) {
+				return SOFIA_TRANSPORT_TCP_TLS;
+			}
+			else if (!strncasecmp(ptr, "sctp", 4)) {
+				return SOFIA_TRANSPORT_SCTP;
+			}
+			break;
+		}
+
+		if ((ptr = strchr(ptr, ';')))
+			ptr++;
+	}
+
+	return (tls) ? SOFIA_TRANSPORT_TCP_TLS : SOFIA_TRANSPORT_UDP;
+}
+
+sofia_transport_t sofia_glue_via2transport(const sip_via_t *via)
+{
+	char *ptr = NULL;
+	int tls = 0;
+
+	if (!via || !via->v_protocol)
+		return SOFIA_TRANSPORT_UNKNOWN;
+
+	if (!strcasecmp(via->v_protocol, "sips")) {
+		tls++;
+	}
+
+	if ((ptr = strrchr(via->v_protocol, '/'))) {
+		ptr++;
+
+		if (!strcasecmp(ptr, "udp")) {
+			return SOFIA_TRANSPORT_UDP;
+		}
+		else if(!strcasecmp(ptr, "tcp")) {
+			return SOFIA_TRANSPORT_TCP;
+		}
+		else if(!strcasecmp(ptr, "tls")) {
+			return SOFIA_TRANSPORT_TCP_TLS;
+		}
+		else if(!strcasecmp(ptr, "sctp")) {
+			return SOFIA_TRANSPORT_SCTP;
+		}
+	}
+
+	return SOFIA_TRANSPORT_UNKNOWN;
+}
+
+#if 0
+sofia_transport_t sofia_glue_uri2transport(const char *uri)
+{
+	char *scheme = NULL, *transport = NULL;
+	int tls = 0;
+
+	if ((scheme = strchr(uri, '<'))) {
+		scheme++;
+	} else {
+		scheme = (char *)uri;
+	}
+
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "scheme: %s\n", scheme);
+
+	if (!strncasecmp(scheme, "sips", 4)) {
+		tls = 1;
+	}
+
+	if (!(transport = strchr(uri, ';'))) {
+		return (tls) ? SOFIA_TRANSPORT_TCP_TLS : SOFIA_TRANSPORT_UDP;
+	} else {
+		transport = strchr(transport, '=');
+		if (transport)
+			transport++;
+	}
+
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "transport: %s\n", transport);
+
+	if (!strncasecmp(transport, "tls", 3)) {
+		return SOFIA_TRANSPORT_TCP_TLS;
+	}
+	else if (!strncasecmp(transport, "tcp", 3)) {
+		return (tls) ? SOFIA_TRANSPORT_TCP_TLS : SOFIA_TRANSPORT_TCP;
+	}
+	else if (!strncasecmp(transport, "sctp", 4)) {
+		return SOFIA_TRANSPORT_SCTP;
+	}
+
+	return (tls) ? SOFIA_TRANSPORT_TCP_TLS : SOFIA_TRANSPORT_UDP;
+}
+#endif
+
+const char *sofia_glue_transport2str(const sofia_transport_t tp)
 {
 	switch(tp) {
 	case SOFIA_TRANSPORT_TCP:
@@ -488,7 +602,7 @@
 	}
 }
 
-static const char *sofia_glue_transport2scheme(const sofia_transport_t tp)
+const char *sofia_glue_transport2scheme(const sofia_transport_t tp)
 {
 	switch (tp) {
 	case SOFIA_TRANSPORT_TCP_TLS:
@@ -499,6 +613,17 @@
 	}
 }
 
+static int sofia_glue_transport_has_tls(const sofia_transport_t tp)
+{
+	switch(tp) {
+	case SOFIA_TRANSPORT_TCP_TLS:
+		return 1;
+
+	default:
+		return 0;
+	}
+}
+
 char *sofia_overcome_sip_uri_weakness(switch_core_session_t *session, const char *uri, const sofia_transport_t transport, switch_bool_t uri_only)
 {
 	char *stripped = switch_core_session_strdup(session, uri);
@@ -611,7 +736,7 @@
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "URL Error! [%s]\n", tech_pvt->dest);
 			return SWITCH_STATUS_FALSE;
 		}
-		
+
 		if ((d_url = sofia_glue_get_url_from_contact(tech_pvt->dest, 1))) {
 			url = d_url;
 		} else {
@@ -620,16 +745,12 @@
 
 		url_str = url;
 
-		if (switch_strlen_zero(tech_pvt->invite_contact)) {
-			tech_pvt->invite_contact = tech_pvt->profile->url;
-		}
-		
 		if (!switch_strlen_zero(tech_pvt->gateway_from_str)) {
 			use_from_str = tech_pvt->gateway_from_str;
 		} else {
 			use_from_str = tech_pvt->from_str;
 		}
-		
+
 		rpid_domain = switch_core_session_strdup(session, use_from_str);
 		sofia_glue_get_url_from_contact(rpid_domain, 0);
 		if ((rpid_domain = strchr(rpid_domain, '@'))) {
@@ -655,12 +776,19 @@
 			}
 		}
 
+		if (switch_strlen_zero(tech_pvt->invite_contact)) {
+			if (sofia_glue_transport_has_tls(transport))
+				tech_pvt->invite_contact = tech_pvt->profile->tls_url;
+			else
+				tech_pvt->invite_contact = tech_pvt->profile->url;
+		}
+
 		url_str = sofia_overcome_sip_uri_weakness(session, url, transport, SWITCH_TRUE);
 		invite_contact = sofia_overcome_sip_uri_weakness(session, tech_pvt->invite_contact, transport, SWITCH_FALSE);
 		from_str = sofia_overcome_sip_uri_weakness(session, use_from_str, 0, SWITCH_FALSE);
 		to_str = sofia_overcome_sip_uri_weakness(session, tech_pvt->dest_to, 0, SWITCH_FALSE);
-		
-		/* 
+
+		/*
 		   Does the "genius" who wanted SIP to be "text-based" so it was "easier to read" even use it now,
 		   or did he just suggest it to make our lives miserable?
 		*/



More information about the Freeswitch-svn mailing list