]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-535: additional checks and use the right contact for registers inside and outside...
authorBrian West <brian@freeswitch.org>
Tue, 23 Nov 2010 15:54:50 +0000 (09:54 -0600)
committerBrian West <brian@freeswitch.org>
Tue, 23 Nov 2010 15:54:50 +0000 (09:54 -0600)
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_reg.c

index 32d25d0ad6d9cd9535359fa89a7f350fc78bab10..4d992b0ea1abc606d5e5cc10dc9d7b8a51555c02 100644 (file)
@@ -2156,6 +2156,30 @@ static void parse_gateways(sofia_profile_t *profile, switch_xml_t gateways_tag)
                                sipip = profile->sipip;
                        }
 
+                       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, 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, proxy);
+                       }
+
+                       /* This checks to make sure we provide the right contact on register for targets behind nat with us. */
+                       if (sofia_test_pflag(profile, PFLAG_AUTO_NAT)) {
+                               char *register_host = NULL;
+
+                               register_host = sofia_glue_get_register_host(gateway->register_proxy);
+
+                               if (register_host && !sofia_glue_check_nat(profile, register_host)) {
+                                       sipip = profile->sipip;
+                               }
+
+                               switch_safe_free(register_host);
+                       }
+
                        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,
@@ -2170,16 +2194,6 @@ static void parse_gateways(sofia_profile_t *profile, switch_xml_t gateways_tag)
                                                                                                                                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, 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, proxy);
-                       }
-
                        gateway->expires_str = switch_core_strdup(gateway->pool, expire_seconds);
 
                        if ((gateway->freq = atoi(gateway->expires_str)) < 5) {
index 14a7bfdd2c5877e8eca022662f927ac2ad8f9ed8..7390378fc8c56ba19a9c5203dcba2bd9a90c958d 100644 (file)
@@ -152,7 +152,7 @@ void sofia_sub_check_gateway(sofia_profile_t *profile, time_t now)
                        register_host = sofia_glue_get_register_host(gateway_ptr->register_proxy);
 
                        /* check for NAT and place a Via header if necessary (hostname or non-local IP) */
-                       if (sofia_glue_check_nat(gateway_ptr->profile, register_host)) {
+                       if (register_host && sofia_glue_check_nat(gateway_ptr->profile, register_host)) {
                                user_via = sofia_glue_create_external_via(NULL, gateway_ptr->profile, gateway_ptr->register_transport);
                        }
 
@@ -295,7 +295,7 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now)
                        register_host = sofia_glue_get_register_host(gateway_ptr->register_proxy);
 
                        /* check for NAT and place a Via header if necessary (hostname or non-local IP) */
-                       if (sofia_glue_check_nat(gateway_ptr->profile, register_host)) {
+                       if (register_host && sofia_glue_check_nat(gateway_ptr->profile, register_host)) {
                                user_via = sofia_glue_create_external_via(NULL, gateway_ptr->profile, gateway_ptr->register_transport);
                        }
 
@@ -358,7 +358,7 @@ void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now)
                        register_host = sofia_glue_get_register_host(gateway_ptr->register_proxy);
 
                        /* check for NAT and place a Via header if necessary (hostname or non-local IP) */
-                       if (sofia_glue_check_nat(gateway_ptr->profile, register_host)) {
+                       if (register_host && sofia_glue_check_nat(gateway_ptr->profile, register_host)) {
                                user_via = sofia_glue_create_external_via(NULL, gateway_ptr->profile, gateway_ptr->register_transport);
                        }