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,
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) {
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);
}
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);
}
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);
}