Revision
14263
Author
anthm
Date
2009-07-15 19:46:35 -0500 (Wed, 15 Jul 2009)

Log Message

sort out proxy stuff SFSIP-165

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c (14262 => 14263)


--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	2009-07-15 22:20:13 UTC (rev 14262)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	2009-07-16 00:46:35 UTC (rev 14263)
@@ -2659,10 +2659,14 @@
 		
 		gateway_ptr->ob_calls++;
 		
-		if (!switch_strlen_zero(gateway_ptr->from_domain)) {
+		if (!switch_strlen_zero(gateway_ptr->from_domain) && !switch_channel_get_variable(nchannel, "sip_invite_domain")) {
 			switch_channel_set_variable(nchannel, "sip_invite_domain", gateway_ptr->from_domain);
 		}
 
+		if (!switch_strlen_zero(gateway_ptr->outbound_sticky_proxy) && !switch_channel_get_variable(nchannel, "sip_route_uri")) {
+			switch_channel_set_variable(nchannel, "sip_route_uri", gateway_ptr->outbound_sticky_proxy);
+		}
+		
 		if (gateway_ptr->ob_vars) {
 			switch_event_header_t *hp;
 			for(hp = gateway_ptr->ob_vars->headers; hp; hp = hp->next) {

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (14262 => 14263)


--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	2009-07-15 22:20:13 UTC (rev 14262)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	2009-07-16 00:46:35 UTC (rev 14263)
@@ -353,6 +353,7 @@
 	char *register_to;
 	char *register_proxy;
 	char *register_sticky_proxy;
+	char *outbound_sticky_proxy;
 	char *register_context;
 	char *expires_str;
 	char *register_url;

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (14262 => 14263)


--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	2009-07-15 22:20:13 UTC (rev 14262)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	2009-07-16 00:46:35 UTC (rev 14263)
@@ -1205,7 +1205,7 @@
 				*context = profile->context,
 				*expire_seconds = "3600",
 				*retry_seconds = "30",
-				*from_user = "", *from_domain = "", *register_proxy = NULL, *contact_host = NULL,
+				*from_user = "", *from_domain = "", *outbound_proxy = NULL, *register_proxy = NULL, *contact_host = NULL,
 				*contact_params = NULL, *params = NULL, *register_transport = NULL;
 			
 			if (!context) {
@@ -1313,6 +1313,8 @@
 					contact_host = val;
 				} else if (!strcmp(var, "register-proxy")) {
 					register_proxy = val;
+				} else if (!strcmp(var, "outbound-proxy")) {
+					outbound_proxy = val;
 				} else if (!strcmp(var, "contact-params")) {
 					contact_params = val;
 				} else if (!strcmp(var, "register-transport")) {
@@ -1385,28 +1387,41 @@
 			
 			if (!switch_strlen_zero(register_proxy)) {
 				if (strncasecmp(register_proxy, "sip:", 4) && strncasecmp(register_proxy, "sips:", 5)) {
-					gateway->register_sticky_proxy = switch_core_sprintf(gateway->pool, "sip:%s", register_proxy);
+					gateway->outbound_sticky_proxy = switch_core_sprintf(gateway->pool, "sip:%s", register_proxy);
 				} else {
-					gateway->register_sticky_proxy = switch_core_strdup(gateway->pool, register_proxy);
+					gateway->outbound_sticky_proxy = switch_core_strdup(gateway->pool, register_proxy);
 				}
 			}
 
+			if (!switch_strlen_zero(outbound_proxy)) {
+				if (strncasecmp(outbound_proxy, "sip:", 4) && strncasecmp(outbound_proxy, "sips:", 5)) {
+					gateway->register_sticky_proxy = switch_core_sprintf(gateway->pool, "sip:%s", outbound_proxy);
+				} else {
+					gateway->register_sticky_proxy = switch_core_strdup(gateway->pool, outbound_proxy);
+				}
+			}
+
 			gateway->retry_seconds = atoi(retry_seconds);
+
 			if (gateway->retry_seconds < 5) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid retry-seconds of %d on gateway %s, using the value of 30 instead.\n",
 								  gateway->retry_seconds, name);
 				gateway->retry_seconds = 30;
 			}
+
 			gateway->register_scheme = switch_core_strdup(gateway->pool, scheme);
 			gateway->register_context = switch_core_strdup(gateway->pool, context);
 			gateway->register_realm = switch_core_strdup(gateway->pool, realm);
 			gateway->register_username = switch_core_strdup(gateway->pool, username);
 			gateway->auth_username = switch_core_strdup(gateway->pool, auth_username);
 			gateway->register_password = switch_core_strdup(gateway->pool, password);
+
 			if (switch_true(caller_id_in_from)) {
 				sofia_set_flag(gateway, REG_FLAG_CALLERID);
 			}
+
 			register_transport = (char *) sofia_glue_transport2str(gateway->register_transport);
+
 			if (contact_params) {
 				if (*contact_params == ';') {
 					params = switch_core_sprintf(gateway->pool, "%s;transport=%s", contact_params, register_transport);
@@ -1421,10 +1436,11 @@
 				gateway->from_domain = switch_core_strdup(gateway->pool, from_domain);
 			}
 
-			gateway->register_url = switch_core_sprintf(gateway->pool, "sip:%s", from_domain ? from_domain : register_proxy ? register_proxy : proxy);
+			gateway->register_url = switch_core_sprintf(gateway->pool, "sip:%s", proxy);
 			gateway->register_from = switch_core_sprintf(gateway->pool, "<sip:%s@%s;transport=%s>", from_user, from_domain, register_transport);
 
 			sipip = contact_host ? contact_host : profile->extsipip ?  profile->extsipip : profile->sipip;
+
 			if (extension_in_contact) {
 				format = strchr(sipip, ':') ? "<sip:%s@[%s]:%d%s>" : "<sip:%s@%s:%d%s>";
 				gateway->register_contact = switch_core_sprintf(gateway->pool, format, extension,
@@ -1438,15 +1454,15 @@
 																sofia_glue_transport_has_tls(gateway->register_transport) ?
 																profile->tls_sip_port : profile->sip_port, params);
 			}
+
 			gateway->extension = switch_core_strdup(gateway->pool, extension);
 			
-			
 			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, from_domain);
+				gateway->register_to = switch_core_sprintf(gateway->pool, "sip:%s@%s", username, proxy + 4);
 			} else {
 				gateway->register_proxy = switch_core_sprintf(gateway->pool, "sip:%s", proxy);
-				gateway->register_to = switch_core_sprintf(gateway->pool, "sip:%s@%s", username, from_domain);
+				gateway->register_to = switch_core_sprintf(gateway->pool, "sip:%s@%s", username, proxy);
 			}
 
 			gateway->expires_str = switch_core_strdup(gateway->pool, expire_seconds);