FS-3688 refactor of cancel handling code in bridge

This commit is contained in:
Anthony Minessale 2011-12-07 17:42:52 -06:00
parent 0bf2a0e975
commit 4e014c4915
2 changed files with 22 additions and 18 deletions

View File

@ -1151,6 +1151,17 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_signal_bridge(switch_core_session_t *
return SWITCH_STATUS_SUCCESS;
}
static void abort_call(switch_channel_t *caller_channel, switch_channel_t *peer_channel)
{
switch_call_cause_t cause = switch_channel_get_cause(caller_channel);
if (!cause) {
cause = SWITCH_CAUSE_ORIGINATOR_CANCEL;
}
switch_channel_hangup(peer_channel, cause);
}
SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_session_t *session,
switch_core_session_t *peer_session,
switch_input_callback_function_t input_callback, void *session_data,
@ -1208,21 +1219,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
switch_channel_test_flag(peer_channel, CF_RING_READY)) {
const char *app, *data;
if (switch_channel_get_state(peer_channel) == CS_CONSUME_MEDIA) {
switch_channel_set_state(peer_channel, CS_HIBERNATE);
switch_channel_wait_for_state(peer_channel, caller_channel, CS_HIBERNATE);
if (!switch_channel_ready(caller_channel)) {
abort_call(caller_channel, peer_channel);
goto done;
}
if (!switch_channel_ready(caller_channel)) {
switch_call_cause_t cause = switch_channel_get_cause(caller_channel);
if (cause) {
switch_channel_hangup(peer_channel, cause);
goto done;
}
}
switch_channel_set_state(peer_channel, CS_CONSUME_MEDIA);
switch_channel_set_variable(peer_channel, "call_uuid", switch_core_session_get_uuid(session));
@ -1241,6 +1242,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
switch_channel_set_variable(caller_channel, SWITCH_LAST_BRIDGE_VARIABLE, switch_core_session_get_uuid(peer_session));
switch_channel_set_variable(peer_channel, SWITCH_LAST_BRIDGE_VARIABLE, switch_core_session_get_uuid(session));
if (!switch_channel_ready(caller_channel)) {
abort_call(caller_channel, peer_channel);
goto done;
}
if (!switch_channel_media_ready(caller_channel) ||
(!switch_channel_test_flag(peer_channel, CF_ANSWERED) && !switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA))) {
if ((status = switch_ivr_wait_for_answer(session, peer_session)) != SWITCH_STATUS_SUCCESS || !switch_channel_ready(caller_channel)) {
@ -1260,6 +1266,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
switch_channel_hangup(caller_channel, SWITCH_CAUSE_ALLOTTED_TIMEOUT);
}
}
abort_call(caller_channel, peer_channel);
switch_core_session_rwunlock(peer_session);
goto done;
}
@ -1279,6 +1286,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
if (switch_core_session_receive_message(peer_session, &msg) != SWITCH_STATUS_SUCCESS) {
status = SWITCH_STATUS_FALSE;
abort_call(caller_channel, peer_channel);
switch_core_session_rwunlock(peer_session);
goto done;
}
@ -1286,6 +1294,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
msg.string_arg = switch_core_session_strdup(session, switch_core_session_get_uuid(peer_session));
if (switch_core_session_receive_message(session, &msg) != SWITCH_STATUS_SUCCESS) {
status = SWITCH_STATUS_FALSE;
abort_call(caller_channel, peer_channel);
switch_core_session_rwunlock(peer_session);
goto done;
}

View File

@ -3510,11 +3510,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
if (*bleg) {
switch_channel_t *bchan = switch_core_session_get_channel(*bleg);
if (switch_channel_get_state(bchan) == CS_CONSUME_MEDIA) {
switch_channel_set_state(bchan, CS_HIBERNATE);
switch_channel_wait_for_state(bchan, caller_channel, CS_HIBERNATE);
}
if (session && caller_channel) {
switch_caller_profile_t *cloned_profile, *peer_profile = switch_channel_get_caller_profile(switch_core_session_get_channel(*bleg));