fix races in bypass media regarding channel signalling that may cause answer to be skipped

This commit is contained in:
Anthony Minessale
2011-08-19 16:25:26 -05:00
parent 5dd9b7218a
commit d43af04e93
8 changed files with 53 additions and 31 deletions

View File

@@ -668,43 +668,51 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_parse_next_event(switch_core_session_
}
SWITCH_DECLARE(switch_status_t) switch_ivr_parse_all_messages(switch_core_session_t *session)
SWITCH_DECLARE(switch_status_t) switch_ivr_process_indications(switch_core_session_t *session, switch_core_session_message_t *message)
{
switch_core_session_message_t *message;
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_channel_t *channel = switch_core_session_get_channel(session);
int i = 0;
switch_ivr_parse_all_signal_data(session);
while (switch_core_session_dequeue_message(session, &message) == SWITCH_STATUS_SUCCESS) {
i++;
switch(message->message_id) {
case SWITCH_MESSAGE_INDICATE_ANSWER:
if (switch_channel_answer(channel) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
switch_core_session_free_message(&message);
break;
case SWITCH_MESSAGE_INDICATE_PROGRESS:
if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
switch_core_session_free_message(&message);
break;
case SWITCH_MESSAGE_INDICATE_RINGING:
if (switch_channel_ring_ready(channel) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
switch_core_session_free_message(&message);
break;
default:
switch_core_session_receive_message(session, message);
status = SWITCH_STATUS_FALSE;
break;
}
message = NULL;
return status;
}
SWITCH_DECLARE(switch_status_t) switch_ivr_parse_all_messages(switch_core_session_t *session)
{
switch_core_session_message_t *message;
int i = 0;
switch_ivr_parse_all_signal_data(session);
while (switch_core_session_dequeue_message(session, &message) == SWITCH_STATUS_SUCCESS) {
i++;
if (switch_ivr_process_indications(session, message) == SWITCH_STATUS_SUCCESS) {
switch_core_session_free_message(&message);
} else {
switch_core_session_receive_message(session, message);
message = NULL;
}
}
return i ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;