From acd0898e323f0a13a6a93c8f1d6d40000d8adce7 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 28 Jun 2011 10:30:11 -0500 Subject: [PATCH] support final response in response header passing --- src/mod/endpoints/mod_sofia/mod_sofia.c | 9 ++++- src/mod/endpoints/mod_sofia/sofia.c | 48 +++++++++++++------------ 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 7d2164548f..5d594094b9 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -517,6 +517,8 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session) TAG_IF(!zstr(reason), SIPTAG_REASON_STR(reason)), TAG_IF(!zstr(bye_headers), SIPTAG_HEADER_STR(bye_headers)), TAG_END()); } } else { + char *resp_headers = sofia_glue_get_extra_headers(channel, SOFIA_SIP_RESPONSE_HEADER_PREFIX); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Responding to INVITE with: %d\n", sip_cause); if (!tech_pvt->got_bye) { switch_channel_set_variable(channel, "sip_hangup_disposition", "send_refuse"); @@ -532,7 +534,12 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session) nua_respond(tech_pvt->nh, sip_cause, sip_status_phrase(sip_cause), TAG_IF(!zstr(reason), SIPTAG_REASON_STR(reason)), - TAG_IF(cid, SIPTAG_HEADER_STR(cid)), TAG_IF(!zstr(bye_headers), SIPTAG_HEADER_STR(bye_headers)), TAG_END()); + TAG_IF(cid, SIPTAG_HEADER_STR(cid)), + TAG_IF(!zstr(bye_headers), SIPTAG_HEADER_STR(bye_headers)), + TAG_IF(!zstr(resp_headers), SIPTAG_HEADER_STR(resp_headers)), + TAG_END()); + + switch_safe_free(resp_headers); } } } diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 2a38fdc130..e40b38cff9 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -4504,8 +4504,33 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status #endif + + if ((status == 180 || status == 183 || status > 199)) { + const char *vval; + + if (status > 199) { + sofia_glue_set_extra_headers(channel, sip, SOFIA_SIP_RESPONSE_HEADER_PREFIX); + } else { + sofia_glue_set_extra_headers(channel, sip, SOFIA_SIP_PROGRESS_HEADER_PREFIX); + } + + + if (!(vval = switch_channel_get_variable(channel, "sip_copy_custom_headers")) || switch_true(vval)) { + switch_core_session_t *other_session; + + if (switch_core_session_get_partner(session, &other_session) == SWITCH_STATUS_SUCCESS) { + if (status > 199) { + switch_ivr_transfer_variable(session, other_session, SOFIA_SIP_RESPONSE_HEADER_PREFIX_T); + } else { + switch_ivr_transfer_variable(session, other_session, SOFIA_SIP_PROGRESS_HEADER_PREFIX_T); + } + switch_core_session_rwunlock(other_session); + } + } + } + if ((status == 180 || status == 183 || status == 200)) { - const char *x_freeswitch_support, *vval; + const char *x_freeswitch_support; switch_channel_set_flag(channel, CF_MEDIA_ACK); @@ -4518,28 +4543,7 @@ static void sofia_handle_sip_r_invite(switch_core_session_t *session, int status } else if (sip->sip_server && sip->sip_server->g_string) { switch_channel_set_variable(channel, "sip_user_agent", sip->sip_server->g_string); } - - if (status == 200) { - sofia_glue_set_extra_headers(channel, sip, SOFIA_SIP_RESPONSE_HEADER_PREFIX); - } else { - sofia_glue_set_extra_headers(channel, sip, SOFIA_SIP_PROGRESS_HEADER_PREFIX); - } - - if (!(vval = switch_channel_get_variable(channel, "sip_copy_custom_headers")) || switch_true(vval)) { - switch_core_session_t *other_session; - - if (switch_core_session_get_partner(session, &other_session) == SWITCH_STATUS_SUCCESS) { - if (status == 200) { - switch_ivr_transfer_variable(session, other_session, SOFIA_SIP_RESPONSE_HEADER_PREFIX_T); - } else { - switch_ivr_transfer_variable(session, other_session, SOFIA_SIP_PROGRESS_HEADER_PREFIX_T); - } - switch_core_session_rwunlock(other_session); - } - } - - sofia_update_callee_id(session, profile, sip, SWITCH_FALSE); if (sofia_test_pflag(tech_pvt->profile, PFLAG_AUTOFIX_TIMING)) {