From 0f16046103e4d332187e2cfee5954a26213c1e47 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 26 Jun 2008 20:19:09 +0000 Subject: [PATCH] add path support to sofia git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8851 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/endpoints/mod_sofia/sofia_glue.c | 42 +++++++++++++++++++++--- src/mod/endpoints/mod_sofia/sofia_reg.c | 27 +++++++++++---- 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index f1b7b86759..6bdd34cc50 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -929,8 +929,9 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) uint32_t session_timeout = 0; const char *val; const char *rep; - char *sticky = NULL; const char *call_id = NULL; + char *route = NULL; + char *route_uri = NULL; rep = switch_channel_get_variable(channel, SOFIA_REPLACES_HEADER); @@ -1056,15 +1057,20 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) use_from_str = from_str; from_str = switch_core_session_sprintf(session, "\"%s\" <%s>", tech_pvt->caller_profile->caller_id_name, use_from_str); - tech_pvt->nh = nua_handle(tech_pvt->profile->nua, NULL, - NUTAG_URL(url_str), SIPTAG_TO_STR(to_str), SIPTAG_FROM_STR(from_str), SIPTAG_CONTACT_STR(invite_contact), TAG_END()); + tech_pvt->nh = nua_handle(tech_pvt->profile->nua, NULL, + NUTAG_URL(url_str), + SIPTAG_TO_STR(to_str), + SIPTAG_FROM_STR(from_str), + SIPTAG_CONTACT_STR(invite_contact), + TAG_END()); + if (strstr(tech_pvt->dest, ";nat") || strstr(tech_pvt->dest, ";received") || ((val = switch_channel_get_variable(channel, "sip_sticky_contact")) && switch_true(val))) { switch_set_flag(tech_pvt, TFLAG_NAT); tech_pvt->record_route = switch_core_session_strdup(tech_pvt->session, url_str); - sticky = tech_pvt->record_route; + route_uri = tech_pvt->record_route; session_timeout = SOFIA_NAT_SESSION_TIMEOUT; switch_channel_set_variable(channel, "sip_nat_detected", "true"); } @@ -1159,6 +1165,31 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) call_id = switch_channel_get_variable(channel, "sip_outgoing_call_id"); + if ((route = strstr(tech_pvt->dest, ";path="))) { + char *p; + route = switch_core_session_strdup(tech_pvt->session, route + 6); + for (p = route; p && *p ; p++) { + if (*p == '>' || *p == ';') { + *p = '\0'; + break; + } + } + switch_url_decode(route); + route_uri = switch_core_session_strdup(tech_pvt->session, route); + if ((p = strchr(route_uri, ','))) { + while (*(p-1) == ' ') { + p--; + } + if (*p) { + *p = '\0'; + } + } + + route_uri = sofia_overcome_sip_uri_weakness(tech_pvt->session, route_uri, 0, SWITCH_TRUE, NULL); + } + + + nua_invite(tech_pvt->nh, NUTAG_AUTOANSWER(0), NUTAG_SESSION_TIMER(session_timeout), @@ -1166,8 +1197,9 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session) TAG_IF(!switch_strlen_zero(alert_info), SIPTAG_HEADER_STR(alert_info)), TAG_IF(!switch_strlen_zero(extra_headers), SIPTAG_HEADER_STR(extra_headers)), TAG_IF(!switch_strlen_zero(max_forwards), SIPTAG_MAX_FORWARDS_STR(max_forwards)), - TAG_IF(sticky, NUTAG_PROXY(tech_pvt->record_route)), TAG_IF(call_id, SIPTAG_CALL_ID_STR(call_id)), + TAG_IF(route_uri, NUTAG_PROXY(route_uri)), + TAG_IF(route, SIPTAG_ROUTE_STR(route)), SOATAG_USER_SDP_STR(tech_pvt->local_sdp_str), SOATAG_REUSE_REJECTED(1), SOATAG_ORDERED_USER(1), diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index f52b012ac3..48a908c5ef 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -409,7 +409,8 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand const char *call_id = NULL; char *force_user; char received_data[128] = ""; - + char *path_val = NULL; + /* 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); @@ -436,6 +437,9 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand const char *port = contact->m_url->url_port; char new_port[25] = ""; const char *contact_host = contact->m_url->url_host; + char *path_encoded = NULL; + int path_encoded_len = 0; + display = contact->m_display; if (is_nat) { @@ -454,6 +458,14 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand } } + if (sip->sip_path) { + path_val = sip_header_as_string(nh->nh_home, (void *) sip->sip_path); + path_encoded_len = (strlen(path_val) * 3) + 1; + switch_zmalloc(path_encoded, path_encoded_len); + switch_copy_string(path_encoded, ";path=", 7); + switch_url_encode(path_val, path_encoded + 6, path_encoded_len - 6); + } + if (port) { switch_snprintf(new_port, sizeof(new_port), ":%s", port); } @@ -463,12 +475,15 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand } if (contact->m_url->url_params) { - switch_snprintf(contact_str, sizeof(contact_str), "%s ", - display, contact->m_url->url_user, contact_host, new_port, contact->m_url->url_params, received_data, is_nat ? ";nat=yes" : ""); + switch_snprintf(contact_str, sizeof(contact_str), "%s ", + display, contact->m_url->url_user, contact_host, new_port, + contact->m_url->url_params, received_data, is_nat ? ";nat=yes" : "", path_encoded ? path_encoded : ""); } else { - switch_snprintf(contact_str, sizeof(contact_str), "%s ", display, contact->m_url->url_user, contact_host, new_port, - received_data, is_nat ? ";nat=yes" : ""); + switch_snprintf(contact_str, sizeof(contact_str), "%s ", display, contact->m_url->url_user, contact_host, new_port, + received_data, is_nat ? ";nat=yes" : "", path_encoded ? path_encoded : ""); } + + switch_safe_free(path_encoded); } if (expires) { @@ -691,7 +706,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand } } - nua_respond(nh, SIP_200_OK, SIPTAG_CONTACT(sip->sip_contact), NUTAG_WITH_THIS(nua), TAG_END()); + nua_respond(nh, SIP_200_OK, SIPTAG_CONTACT(sip->sip_contact), TAG_IF(path_val, SIPTAG_PATH_STR(path_val)), NUTAG_WITH_THIS(nua), TAG_END()); if (s_event) { switch_event_fire(&s_event);