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

Freeswitch SVN anthm at freeswitch.org
Tue Oct 23 10:22:53 EDT 2007


Author: anthm
Date: Tue Oct 23 10:22:53 2007
New Revision: 6026

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

Log:
whoever thought making SIP all text based was simply a genius, umm no, that was sarcasm

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	Tue Oct 23 10:22:53 2007
@@ -548,7 +548,8 @@
 				*from_domain = "",
 				*register_proxy = NULL,
 				*contact_params = NULL,
-				*params = NULL;
+				*params = NULL,
+				*register_transport = "udp";
 			
 			gateway->pool = profile->pool;
 			gateway->profile = profile;
@@ -588,6 +589,13 @@
 					register_proxy = val;
 				} else if (!strcmp(var, "contact-params")) {
 					contact_params = val;
+				} else if (!strcmp(var, "register-transport")) {
+					if (!strcasecmp(val, "udp") || !strcasecmp(val, "tcp")) {
+						register_transport = val;
+					} else {
+						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERROR: unsupported transport\n");
+						goto skip;
+					}
 				}
 			}
 			
@@ -640,21 +648,21 @@
 			}
 			if (contact_params) {
 				if (*contact_params == ';') {
-					params = contact_params;
+					params = switch_core_sprintf(gateway->pool, "%s&transport=%s", contact_params, register_transport);
 				} else {
-					params = switch_core_sprintf(gateway->pool, ";%s", contact_params);
+					params = switch_core_sprintf(gateway->pool, ";%s&transport=%s", contact_params, register_transport);
 				}
 			} else {
-				params = "";
+				params = switch_core_sprintf(gateway->pool, ";transport=%s", register_transport);
 			}
 			
 
-			gateway->register_url = switch_core_sprintf(gateway->pool, "sip:%s", register_proxy);
-			gateway->register_from = switch_core_sprintf(gateway->pool, "sip:%s@%s", username, from_domain);
+			gateway->register_url = switch_core_sprintf(gateway->pool, "sip:%s;transport=%s", register_proxy,register_transport);
+			gateway->register_from = switch_core_sprintf(gateway->pool, "<sip:%s@%s;transport=%s>", username, from_domain, register_transport);
 			gateway->register_contact = switch_core_sprintf(gateway->pool, "<sip:%s@%s:%d%s>", extension,
 															profile->extsipip ? profile->extsipip : profile->sipip, profile->sip_port, params);
 
-
+			
 			if (!strncasecmp(proxy, "sip:", 4)) {
                 gateway->register_proxy = switch_core_strdup(gateway->pool, proxy);
                 gateway->register_to = switch_core_sprintf(gateway->pool, "sip:%s@%s", username, proxy + 4);

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	Tue Oct 23 10:22:53 2007
@@ -549,6 +549,9 @@
 	if (!tech_pvt->nh) {
 		char *d_url = NULL, *url = NULL;
 		sofia_private_t *sofia_private;
+		char *invite_contact = NULL, *to_str, *use_from_str, *from_str, *url_str;
+		char *transport = "udp", *t_var;
+
 		if (switch_strlen_zero(tech_pvt->dest)) {
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "URL Error! [%s]\n", tech_pvt->dest);
 			return SWITCH_STATUS_FALSE;
@@ -560,29 +563,52 @@
 			url = tech_pvt->dest;
 		}
 
+		url_str = url;
+
 		if (switch_strlen_zero(tech_pvt->invite_contact)) {
 			tech_pvt->invite_contact = tech_pvt->profile->url;
 		}
 		
-		if (switch_stristr("port=tcp", url)) {
-			char *tmp;
+		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;
+		}
 
-			if (strchr(tech_pvt->invite_contact, ';')) {
-				tmp = switch_core_session_sprintf(session, "<%s&transport=tcp>", tech_pvt->invite_contact);
-			} else {
-				tmp = switch_core_session_sprintf(session, "<%s;transport=tcp>", tech_pvt->invite_contact);
+		if (switch_stristr("port=tcp", url)) {
+			transport = "tcp";
+		} else {
+			if ((t_var = switch_channel_get_variable(channel, "sip_transport"))) {
+				if (!strcasecmp(t_var, "tcp") || !strcasecmp(t_var, "udp")) {
+					transport = t_var;
+				}
 			}
-			assert(tmp);
-			tech_pvt->invite_contact = tmp;
+			url_str = switch_core_session_sprintf(session, "%s;transport=%s", url, transport);
 		}
 		
+		if (strchr(tech_pvt->invite_contact, ';')) {
+			invite_contact = switch_core_session_sprintf(session, "<%s&transport=%s>", tech_pvt->invite_contact, transport);
+		} else {
+			invite_contact = switch_core_session_sprintf(session, "<%s;transport=%s>", tech_pvt->invite_contact, transport);
+		}
+		
+		if (strchr(use_from_str, '>')) {
+			from_str = switch_core_session_sprintf(session, "%s;transport=%s", use_from_str, transport);
+		} else {
+			from_str = switch_core_session_sprintf(session, "<%s;transport=%s>", use_from_str, transport);
+		}
+
+		if (strchr(tech_pvt->dest_to, '>')) {
+			to_str = switch_core_session_sprintf(session, "%s;transport=%s", tech_pvt->dest_to, transport);
+		} else {
+			to_str = switch_core_session_sprintf(session, "<%s;transport=%s>", tech_pvt->dest_to, transport);
+		}
 
 		tech_pvt->nh = nua_handle(tech_pvt->profile->nua, NULL,
-								  NUTAG_URL(url),
-								  SIPTAG_TO_STR(tech_pvt->dest_to),
-								  TAG_IF(tech_pvt->gateway_from_str, SIPTAG_FROM_STR(tech_pvt->gateway_from_str)),
-								  TAG_IF(!tech_pvt->gateway_from_str, SIPTAG_FROM_STR(tech_pvt->from_str)),
-								  SIPTAG_CONTACT_STR(tech_pvt->invite_contact),
+								  NUTAG_URL(url_str),
+								  SIPTAG_TO_STR(to_str),
+								  SIPTAG_FROM_STR(from_str),
+								  SIPTAG_CONTACT_STR(invite_contact),
 								  TAG_END());
 
 		switch_safe_free(d_url);

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	Tue Oct 23 10:22:53 2007
@@ -75,6 +75,7 @@
 			nua_unregister(gateway_ptr->nh,
 						   NUTAG_URL(gateway_ptr->register_url),
 						   SIPTAG_FROM_STR(gateway_ptr->register_from),
+						   SIPTAG_TO_STR(gateway_ptr->register_from),
 						   SIPTAG_CONTACT_STR(gateway_ptr->register_contact),
 						   SIPTAG_EXPIRES_STR(gateway_ptr->expires_str),
 						   NUTAG_REGISTRAR(gateway_ptr->register_proxy),
@@ -99,6 +100,7 @@
 				if (now) {
 					nua_register(gateway_ptr->nh,
 								 NUTAG_URL(gateway_ptr->register_url),
+								 SIPTAG_TO_STR(gateway_ptr->register_from),
 								 SIPTAG_FROM_STR(gateway_ptr->register_from),
 								 SIPTAG_CONTACT_STR(gateway_ptr->register_contact),
 								 SIPTAG_EXPIRES_STR(gateway_ptr->expires_str),
@@ -109,6 +111,7 @@
 					nua_unregister(gateway_ptr->nh,
 								   NUTAG_URL(gateway_ptr->register_url),
 								   SIPTAG_FROM_STR(gateway_ptr->register_from),
+								   SIPTAG_TO_STR(gateway_ptr->register_from),
 								   SIPTAG_CONTACT_STR(gateway_ptr->register_contact),
 								   SIPTAG_EXPIRES_STR(gateway_ptr->expires_str),
 								   NUTAG_REGISTRAR(gateway_ptr->register_proxy),



More information about the Freeswitch-svn mailing list