[Freeswitch-svn] [commit] r8851 - freeswitch/trunk/src/mod/endpoints/mod_sofia

Freeswitch SVN anthm at freeswitch.org
Thu Jun 26 16:19:09 EDT 2008


Author: anthm
Date: Thu Jun 26 16:19:09 2008
New Revision: 8851

Modified:
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c

Log:
add path support to sofia

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	Thu Jun 26 16:19:09 2008
@@ -929,8 +929,9 @@
 	uint32_t session_timeout = 0;
 	const char *val;
 	const char *rep;
-	char *sticky = NULL;
 	const char *call_id = NULL;
+	char *route = NULL;
+	char *route_uri = NULL;
 
 	rep = switch_channel_get_variable(channel, SOFIA_REPLACES_HEADER);
 
@@ -1056,15 +1057,20 @@
 		use_from_str = from_str;
 		from_str = switch_core_session_sprintf(session, "\"%s\" <%s>", tech_pvt->caller_profile->caller_id_name, use_from_str);
 		
-		tech_pvt->nh = nua_handle(tech_pvt->profile->nua, NULL,
-								  NUTAG_URL(url_str), SIPTAG_TO_STR(to_str), SIPTAG_FROM_STR(from_str), SIPTAG_CONTACT_STR(invite_contact), TAG_END());
 
+		tech_pvt->nh = nua_handle(tech_pvt->profile->nua, NULL,
+								  NUTAG_URL(url_str),
+								  SIPTAG_TO_STR(to_str), 
+								  SIPTAG_FROM_STR(from_str),
+								  SIPTAG_CONTACT_STR(invite_contact),
+								  TAG_END());
+		
 
 		if (strstr(tech_pvt->dest, ";nat") || strstr(tech_pvt->dest, ";received") 
 			|| ((val = switch_channel_get_variable(channel, "sip_sticky_contact")) && switch_true(val))) {
 			switch_set_flag(tech_pvt, TFLAG_NAT);
 			tech_pvt->record_route = switch_core_session_strdup(tech_pvt->session, url_str);
-			sticky = tech_pvt->record_route;
+			route_uri = tech_pvt->record_route;
 			session_timeout = SOFIA_NAT_SESSION_TIMEOUT;
 			switch_channel_set_variable(channel, "sip_nat_detected", "true");
 		}
@@ -1159,6 +1165,31 @@
 
 	call_id = switch_channel_get_variable(channel, "sip_outgoing_call_id");
 
+	if ((route = strstr(tech_pvt->dest, ";path="))) {
+		char *p;
+		route = switch_core_session_strdup(tech_pvt->session, route + 6);
+		for (p = route; p && *p ; p++) {
+			if (*p == '>' || *p == ';') {
+				*p = '\0';
+				break;
+			}
+		}
+		switch_url_decode(route);
+		route_uri = switch_core_session_strdup(tech_pvt->session, route);
+		if ((p = strchr(route_uri, ','))) {
+			while (*(p-1) == ' ') {
+				p--;
+			}
+			if (*p) {
+				*p = '\0';
+			}
+		}
+		
+		route_uri = sofia_overcome_sip_uri_weakness(tech_pvt->session, route_uri, 0, SWITCH_TRUE, NULL);
+	}
+	
+	
+
 	nua_invite(tech_pvt->nh,
 			   NUTAG_AUTOANSWER(0),
 			   NUTAG_SESSION_TIMER(session_timeout),
@@ -1166,8 +1197,9 @@
 			   TAG_IF(!switch_strlen_zero(alert_info), SIPTAG_HEADER_STR(alert_info)),
 			   TAG_IF(!switch_strlen_zero(extra_headers), SIPTAG_HEADER_STR(extra_headers)),
 			   TAG_IF(!switch_strlen_zero(max_forwards), SIPTAG_MAX_FORWARDS_STR(max_forwards)),
-			   TAG_IF(sticky, NUTAG_PROXY(tech_pvt->record_route)),
 			   TAG_IF(call_id, SIPTAG_CALL_ID_STR(call_id)),
+			   TAG_IF(route_uri, NUTAG_PROXY(route_uri)),
+			   TAG_IF(route, SIPTAG_ROUTE_STR(route)),
 			   SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str),
 			   SOATAG_REUSE_REJECTED(1),
 			   SOATAG_ORDERED_USER(1),

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c	Thu Jun 26 16:19:09 2008
@@ -409,7 +409,8 @@
 	const char *call_id = NULL;
 	char *force_user;
 	char received_data[128] = "";
-
+	char *path_val = NULL;
+	
 	/* all callers must confirm that sip, sip->sip_request and sip->sip_contact are not NULL */
 	switch_assert(sip != NULL && sip->sip_contact != NULL && sip->sip_request != NULL);
 
@@ -436,6 +437,9 @@
 		const char *port = contact->m_url->url_port;
 		char new_port[25] = "";
 		const char *contact_host = contact->m_url->url_host;
+		char *path_encoded = NULL;
+		int path_encoded_len = 0;
+
 		display = contact->m_display;
 
 		if (is_nat) {
@@ -454,6 +458,14 @@
 			}
 		}
 
+		if (sip->sip_path) {
+			path_val = sip_header_as_string(nh->nh_home, (void *) sip->sip_path);
+			path_encoded_len = (strlen(path_val) * 3) + 1;
+			switch_zmalloc(path_encoded, path_encoded_len);
+			switch_copy_string(path_encoded, ";path=", 7);
+			switch_url_encode(path_val, path_encoded + 6, path_encoded_len - 6);
+		}
+
 		if (port) {
 			switch_snprintf(new_port, sizeof(new_port), ":%s", port);
 		}
@@ -463,12 +475,15 @@
 		}
 
 		if (contact->m_url->url_params) {
-			switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s%s;%s%s%s>",
-							display, contact->m_url->url_user, contact_host, new_port, contact->m_url->url_params, received_data, is_nat ? ";nat=yes" : "");
+			switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s%s;%s%s%s%s>",
+							display, contact->m_url->url_user, contact_host, new_port, 
+							contact->m_url->url_params, received_data, is_nat ? ";nat=yes" : "", path_encoded ? path_encoded : "");
 		} else {
-			switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s%s%s%s>", display, contact->m_url->url_user, contact_host, new_port,
-							received_data, is_nat ? ";nat=yes" : "");
+			switch_snprintf(contact_str, sizeof(contact_str), "%s <sip:%s@%s%s%s%s%s>", display, contact->m_url->url_user, contact_host, new_port,
+							received_data, is_nat ? ";nat=yes" : "", path_encoded ? path_encoded : "");
 		}
+
+		switch_safe_free(path_encoded);
 	}
 
 	if (expires) {
@@ -691,7 +706,7 @@
 			}
 		}
 		
-		nua_respond(nh, SIP_200_OK, SIPTAG_CONTACT(sip->sip_contact), NUTAG_WITH_THIS(nua), TAG_END());
+		nua_respond(nh, SIP_200_OK, SIPTAG_CONTACT(sip->sip_contact), TAG_IF(path_val, SIPTAG_PATH_STR(path_val)), NUTAG_WITH_THIS(nua), TAG_END());
 
 		if (s_event) {
 			switch_event_fire(&s_event);



More information about the Freeswitch-svn mailing list