From f2e8d4421885296539f21a3c728ed505e46c67e0 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 22 May 2008 17:24:10 +0000 Subject: [PATCH] sigh git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8527 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/endpoints/mod_sofia/mod_sofia.h | 3 +- src/mod/endpoints/mod_sofia/sofia.c | 2 + src/mod/endpoints/mod_sofia/sofia_reg.c | 70 +++++++++++++++---------- 3 files changed, 46 insertions(+), 29 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index de06c17c9c..ae285a7a78 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -146,7 +146,8 @@ typedef enum { PFLAG_UNREG_OPTIONS_FAIL = (1 << 18), PFLAG_DISABLE_TIMER = (1 << 19), PFLAG_DISABLE_100REL = (1 << 20), - PFLAG_AGGRESSIVE_NAT_DETECTION = (1 << 21) + PFLAG_AGGRESSIVE_NAT_DETECTION = (1 << 21), + PFLAG_RECIEVED_IN_NAT_REG_CONTACT = (1 << 22) } PFLAGS; typedef enum { diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 9c1655f8fa..419b076f24 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -1117,6 +1117,8 @@ switch_status_t config_sofia(int reload, char *profile_name) switch_set_flag(profile, TFLAG_LATE_NEGOTIATION); } else if (!strcasecmp(var, "inbound-proxy-media") && switch_true(val)) { switch_set_flag(profile, TFLAG_PROXY_MEDIA); + } else if (!strcasecmp(var, "received-in-nat-reg-contact") && switch_true(val)) { + profile->pflags |= PFLAG_RECIEVED_IN_NAT_REG_CONTACT; } else if (!strcasecmp(var, "aggressive-nat-detection") && switch_true(val)) { profile->pflags |= PFLAG_AGGRESSIVE_NAT_DETECTION; } else if (!strcasecmp(var, "rfc2833-pt")) { diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index 97d61355fa..60055a9d47 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -439,7 +439,7 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han const char *reg_desc = "Registered"; const char *call_id = NULL; char *force_user; - + /* all callers must confirm that sip, sip->sip_request and sip->sip_contact are not NULL */ switch_assert(sip != NULL && sip->sip_contact != NULL && sip->sip_request != NULL); @@ -704,43 +704,57 @@ uint8_t sofia_reg_handle_register(nua_t * nua, sofia_profile_t *profile, nua_han if (regtype == REG_REGISTER) { char *new_contact = NULL; - char *p; + char new_port[30] = ""; + char received_data[128] = ""; + char exp_param[128] = ""; + + if (exptime) { + switch_snprintf(exp_param, sizeof(exp_param), ";expires=%ld", exptime); + } + - if ((p = strstr(contact_str, ";nat"))) { - *p = '\0'; + if (contact->m_url->url_port) { + switch_snprintf(new_port, sizeof(new_port), ":%s", contact->m_url->url_port); } + if ((is_nat || nat_hack) && (profile->pflags & PFLAG_RECIEVED_IN_NAT_REG_CONTACT)) { + switch_snprintf(received_data, sizeof(received_data), ";received=\"%s:%d\"", network_ip, network_port); + } + + if (contact->m_url->url_params) { + new_contact = switch_mprintf("%s %s%s", + display, contact->m_url->url_user, contact->m_url->url_host, new_port, contact->m_url->url_params, + exp_param, received_data); + } else { + new_contact = switch_mprintf("%s %s%s", + display, contact->m_url->url_user, contact->m_url->url_host, new_port, + exp_param, received_data); + } + + nua_respond(nh, + SIP_200_OK, + SIPTAG_CONTACT_STR(new_contact), NUTAG_WITH_THIS(nua), TAG_END()); + switch_safe_free(new_contact); + if (exptime) { - if (is_nat || nat_hack) { - new_contact = switch_mprintf("%s;expires=%ld;received=\"%s:%d\"", contact_str, (long)exptime, network_ip, network_port); - } else { - new_contact = switch_mprintf("%s;expires=%ld", contact_str, (long)exptime); - } - nua_respond(nh, - SIP_200_OK, - SIPTAG_CONTACT_STR(new_contact), NUTAG_WITH_THIS(nua), TAG_END()); - switch_safe_free(new_contact); if (switch_event_create(&event, SWITCH_EVENT_MESSAGE_QUERY) == SWITCH_STATUS_SUCCESS) { switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Message-Account", "sip:%s@%s", to_user, to_host); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "VM-Sofia-Profile", "%s", profile->name); switch_event_fire(&event); - } - } else { - nua_respond(nh, - SIP_200_OK, - SIPTAG_CONTACT(contact), NUTAG_WITH_THIS(nua), TAG_END()); - - if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_UNREGISTER) == SWITCH_STATUS_SUCCESS) { - switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "profile-name", "%s", profile->name); - switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from-user", "%s", to_user); - switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from-host", "%s", to_host); - switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "contact", "%s", contact_str); - switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "call-id", "%s", call_id); - switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "rpid", "%s", rpid); - switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "expires", "%ld", (long) exptime); - switch_event_fire(&s_event); + } else { + if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_UNREGISTER) == SWITCH_STATUS_SUCCESS) { + switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "profile-name", "%s", profile->name); + switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from-user", "%s", to_user); + switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "from-host", "%s", to_host); + switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "contact", "%s", contact_str); + switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "call-id", "%s", call_id); + switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "rpid", "%s", rpid); + switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "expires", "%ld", (long) exptime); + switch_event_fire(&s_event); + } } } + return 1; }