From 36cee285b0c11c08e1aae1184f38b31bdda1aaa5 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 8 Sep 2012 16:12:35 -0500 Subject: [PATCH] FS-4602 --resolve --- src/mod/endpoints/mod_sofia/sofia.c | 40 ++++++++++++++++++----------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 79a925f4f8..c95a00b820 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -1716,26 +1716,36 @@ void sofia_event_callback(nua_event_t event, switch_core_session_t *session; if ((session = switch_core_session_locate(sofia_private->uuid))) { - private_object_t *tech_pvt = switch_core_session_get_private(session); switch_channel_t *channel = switch_core_session_get_channel(session); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "detaching session %s\n", sofia_private->uuid); - set_call_id(tech_pvt, sip); + int end = 0; - if (!zstr(tech_pvt->call_id)) { - tech_pvt->sofia_private = NULL; - tech_pvt->nh = NULL; - sofia_set_flag(tech_pvt, TFLAG_BYE); - switch_mutex_lock(profile->flag_mutex); - switch_core_hash_insert(profile->chat_hash, tech_pvt->call_id, strdup(switch_core_session_get_uuid(session))); - switch_mutex_unlock(profile->flag_mutex); - switch_core_session_rwunlock(session); - } else { - switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); + if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND && !switch_channel_test_flag(channel, CF_ANSWERED)) { + private_object_t *tech_pvt = switch_core_session_get_private(session); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "detaching session %s\n", sofia_private->uuid); + + if (!zstr(tech_pvt->call_id)) { + tech_pvt->sofia_private = NULL; + tech_pvt->nh = NULL; + sofia_set_flag(tech_pvt, TFLAG_BYE); + switch_mutex_lock(profile->flag_mutex); + switch_core_hash_insert(profile->chat_hash, tech_pvt->call_id, strdup(switch_core_session_get_uuid(session))); + switch_mutex_unlock(profile->flag_mutex); + } else { + switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); + } + + end++; + } + + switch_core_session_rwunlock(session); + + if (end) { + goto end; } } } - goto end; + break; case nua_i_invite: case nua_i_register: case nua_i_options: