From 92644dbb4dd10499cc00a08fef9ccecba3e750a8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 13 Sep 2016 15:54:55 -0500 Subject: [PATCH] FS-9506 code was too over-zealous about taking control when it should not, pass 2 --- src/mod/endpoints/mod_sofia/sofia.c | 107 +++++++++++++++------------- 1 file changed, 57 insertions(+), 50 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 7b1712ee32..0983bc4301 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -7688,44 +7688,45 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); } goto done; - } else { - if (switch_channel_test_app_flag_key("T38", tech_pvt->channel, CF_APP_T38_NEGOTIATED)) { - nua_respond(tech_pvt->nh, SIP_200_OK, TAG_END()); - goto done; + } else { + int hold_related = 0; + + if (sofia_test_flag(tech_pvt, TFLAG_SIP_HOLD)) { + hold_related = 2; + } else if (switch_stristr("sendonly", r_sdp) || switch_stristr("0.0.0.0", r_sdp) || switch_stristr("inactive", r_sdp)) { + hold_related = 1; } + + if (!is_t38 && hold_related && switch_core_session_get_partner(session, &other_session) == SWITCH_STATUS_SUCCESS) { + if (switch_core_session_compare(session, other_session)) { + switch_core_session_message_t *msg; + const char *hold_msg = "hold"; + private_object_t *other_tech_pvt = switch_core_session_get_private(other_session); - if (!is_t38 && sofia_test_pflag(profile, PFLAG_PROXY_HOLD)) { - if (switch_core_session_get_partner(session, &other_session) == SWITCH_STATUS_SUCCESS) { - if (switch_core_session_compare(session, other_session)) { - if (switch_stristr("sendonly", r_sdp) || switch_stristr("0.0.0.0", r_sdp) || switch_stristr("inactive", r_sdp)) { - switch_core_session_message_t *msg; - const char *hold_msg = "hold"; - private_object_t *other_tech_pvt = switch_core_session_get_private(other_session); - - if (tech_pvt->mparams.num_codecs){ - match = sofia_media_negotiate_sdp(session, r_sdp, SDP_TYPE_REQUEST); - } + if (sofia_test_pflag(profile, PFLAG_PROXY_HOLD)) { + switch_channel_set_flag(tech_pvt->channel, CF_REINVITE); - if (!match) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Reinvite Codec Error!\n"); - nua_respond(tech_pvt->nh, SIP_488_NOT_ACCEPTABLE, TAG_END()); - goto done; - } - - switch_channel_set_flag(tech_pvt->channel, CF_REINVITE); - - msg = switch_core_session_alloc(other_session, sizeof(*msg)); - - if (switch_stristr("inactive", r_sdp)) { - sofia_set_flag_locked(other_tech_pvt, TFLAG_SIP_HOLD_INACTIVE); - //switch_channel_set_variable(channel, "sofia_hold_inactive", "true"); - } else { - sofia_clear_flag_locked(other_tech_pvt, TFLAG_SIP_HOLD_INACTIVE); - } + if (tech_pvt->mparams.num_codecs){ + match = sofia_media_negotiate_sdp(session, r_sdp, SDP_TYPE_REQUEST); + } + if (!match) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Reinvite Codec Error!\n"); + nua_respond(tech_pvt->nh, SIP_488_NOT_ACCEPTABLE, TAG_END()); + goto done; + } + + msg = switch_core_session_alloc(other_session, sizeof(*msg)); + + if (switch_stristr("inactive", r_sdp)) { + sofia_set_flag_locked(other_tech_pvt, TFLAG_SIP_HOLD_INACTIVE); + //switch_channel_set_variable(channel, "sofia_hold_inactive", "true"); + } else { + sofia_clear_flag_locked(other_tech_pvt, TFLAG_SIP_HOLD_INACTIVE); + } + if (hold_related == 1) { msg->message_id = SWITCH_MESSAGE_INDICATE_HOLD; - if (sofia_test_pflag(profile, PFLAG_MANAGE_SHARED_APPEARANCE)) { const char *info = switch_channel_get_variable(channel, "presence_call_info"); @@ -7735,7 +7736,6 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, } } } - sofia_set_flag_locked(tech_pvt, TFLAG_SIP_HOLD); switch_channel_set_flag(channel, CF_LEG_HOLDING); switch_channel_presence(tech_pvt->channel, "unknown", hold_msg, NULL); @@ -7746,29 +7746,36 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status, switch_channel_clear_flag(channel, CF_LEG_HOLDING); switch_channel_presence(tech_pvt->channel, "unknown", hold_msg, NULL); } - msg->from = __FILE__; switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Indicating %s to other leg.\n%s\n", hold_msg, r_sdp); + switch_core_session_queue_message(other_session, msg); - } - switch_core_session_rwunlock(other_session); + + + + switch_core_media_gen_local_sdp(session, SDP_TYPE_RESPONSE, NULL, 0, NULL, 0); + if (sofia_use_soa(tech_pvt)){ + nua_respond(tech_pvt->nh, SIP_200_OK, + SIPTAG_CONTACT_STR(tech_pvt->reply_contact), + SOATAG_USER_SDP_STR(tech_pvt->mparams.local_sdp_str), + SOATAG_REUSE_REJECTED(1), + SOATAG_AUDIO_AUX("cn telephone-event"), + TAG_IF(sofia_test_pflag(profile, PFLAG_DISABLE_100REL), NUTAG_INCLUDE_EXTRA_SDP(1)), TAG_END()); + } else { + nua_respond(tech_pvt->nh, SIP_200_OK, + NUTAG_MEDIA_ENABLE(0), + SIPTAG_CONTACT_STR(tech_pvt->reply_contact), + SIPTAG_CONTENT_TYPE_STR("application/sdp"), SIPTAG_PAYLOAD_STR(tech_pvt->mparams.local_sdp_str), TAG_END()); + } + goto done; + } } - switch_core_media_gen_local_sdp(session, SDP_TYPE_RESPONSE, NULL, 0, NULL, 0); + switch_core_session_rwunlock(other_session); + } - if (sofia_use_soa(tech_pvt)){ - nua_respond(tech_pvt->nh, SIP_200_OK, - SIPTAG_CONTACT_STR(tech_pvt->reply_contact), - SOATAG_USER_SDP_STR(tech_pvt->mparams.local_sdp_str), - SOATAG_REUSE_REJECTED(1), - SOATAG_AUDIO_AUX("cn telephone-event"), - TAG_IF(sofia_test_pflag(profile, PFLAG_DISABLE_100REL), NUTAG_INCLUDE_EXTRA_SDP(1)), TAG_END()); - } else { - nua_respond(tech_pvt->nh, SIP_200_OK, - NUTAG_MEDIA_ENABLE(0), - SIPTAG_CONTACT_STR(tech_pvt->reply_contact), - SIPTAG_CONTENT_TYPE_STR("application/sdp"), SIPTAG_PAYLOAD_STR(tech_pvt->mparams.local_sdp_str), TAG_END()); - } + if (switch_channel_test_app_flag_key("T38", tech_pvt->channel, CF_APP_T38_NEGOTIATED)) { + nua_respond(tech_pvt->nh, SIP_200_OK, TAG_END()); goto done; }