return ret;
}
+char *sofia_glue_get_register_host(const char *uri)
+{
+ char *register_host = NULL;
+ const char *s;
+ char *p = NULL;
+
+ if ((s = switch_stristr("sip:", uri))) {
+ s += 4;
+ } else if ((s = switch_stristr("sips:", uri))) {
+ s += 5;
+ }
+
+ if (!s) {
+ return NULL;
+ }
+
+ register_host = strdup(s);
+
+ /* remove port for register_host for testing nat acl take into account
+ ipv6 addresses which are required to have brackets around the addr
+ */
+ if ((p = strchr(register_host, ']')) && (*(p + 1) == ':')) {
+ *(p + 1) = '\0';
+ } else {
+ if ((p = strrchr(register_host, ':'))) {
+ *p = '\0';
+ }
+ }
+
+ /* register_proxy should always start with "sip:" or "sips:" */
+ assert(register_host);
+
+ return register_host;
+}
+
const char *sofia_glue_strip_proto(const char *uri)
{
char *p;
}
}
-
void sofia_glue_build_vid_refresh_message(switch_core_session_t *session, const char *pl)
{
switch_core_session_message_t *msg;
int ss_state = nua_callstate_authenticating;
sub_state_t ostate = gw_sub_ptr->state;
char *user_via = NULL;
+ char *register_host = NULL;
if (!now) {
gw_sub_ptr->state = ostate = SUB_STATE_UNSUBED;
gw_sub_ptr->expires_str = "0";
}
- if (sofia_glue_check_nat(gateway_ptr->profile, gateway_ptr->register_proxy)) {
+ 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)) {
user_via = sofia_glue_create_external_via(NULL, gateway_ptr->profile, gateway_ptr->register_transport);
}
+ switch_safe_free(register_host);
+
switch (ostate) {
case SUB_STATE_NOSUB:
break;
nua_handle_bind(gateway_ptr->nh, gateway_ptr->sofia_private);
if (now) {
- nua_subscribe(gateway_ptr->sub_nh, NUTAG_URL(gateway_ptr->register_url), TAG_IF(user_via, SIPTAG_VIA_STR(user_via)), SIPTAG_EVENT_STR(gw_sub_ptr->event), SIPTAG_ACCEPT_STR(gw_sub_ptr->content_type), SIPTAG_TO_STR(gateway_ptr->register_from), SIPTAG_FROM_STR(gateway_ptr->register_from), SIPTAG_CONTACT_STR(gateway_ptr->register_contact), SIPTAG_EXPIRES_STR(gw_sub_ptr->expires_str), // sofia stack bases its auto-refresh stuff on this
+ nua_subscribe(gateway_ptr->sub_nh,
+ NUTAG_URL(gateway_ptr->register_url),
+ TAG_IF(user_via, SIPTAG_VIA_STR(user_via)),
+ SIPTAG_EVENT_STR(gw_sub_ptr->event),
+ SIPTAG_ACCEPT_STR(gw_sub_ptr->content_type),
+ SIPTAG_TO_STR(gateway_ptr->register_from),
+ SIPTAG_FROM_STR(gateway_ptr->register_from),
+ SIPTAG_CONTACT_STR(gateway_ptr->register_contact),
+ SIPTAG_EXPIRES_STR(gw_sub_ptr->expires_str), /* sofia stack bases its auto-refresh stuff on this */
TAG_NULL());
gw_sub_ptr->retry = now + gw_sub_ptr->retry_seconds;
} else {
for (gateway_ptr = profile->gateways; gateway_ptr; gateway_ptr = gateway_ptr->next) {
reg_state_t ostate = gateway_ptr->state;
char *user_via = NULL;
+ char *register_host = NULL;
if (!now) {
gateway_ptr->state = ostate = REG_STATE_UNREGED;
nua_handle_t *nh = nua_handle(profile->nua, NULL, NUTAG_URL(gateway_ptr->register_url), TAG_END());
sofia_private_t *pvt;
- if (sofia_glue_check_nat(gateway_ptr->profile, gateway_ptr->register_proxy)) {
+ 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)) {
user_via = sofia_glue_create_external_via(NULL, gateway_ptr->profile, gateway_ptr->register_transport);
}
+ switch_safe_free(register_host);
+
pvt = malloc(sizeof(*pvt));
switch_assert(pvt);
memset(pvt, 0, sizeof(*pvt));
sofia_reg_new_handle(gateway_ptr, now ? 1 : 0);
}
- if (sofia_glue_check_nat(gateway_ptr->profile, gateway_ptr->register_proxy)) {
+ 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)) {
user_via = sofia_glue_create_external_via(NULL, gateway_ptr->profile, gateway_ptr->register_transport);
}
+ switch_safe_free(register_host);
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Registering %s\n", gateway_ptr->name);
if (now) {