[Core] switch_ivr: Restrict the misuse of uuid_hold API. Add switch_hold unit-test.

This commit is contained in:
Andrey Volk
2021-08-12 18:02:41 +03:00
parent 6040f3bf48
commit fcaaf20c7d
7 changed files with 311 additions and 8 deletions
@@ -7896,6 +7896,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
switch_console_set_complete("add uuid_flush_dtmf ::console::list_uuid");
switch_console_set_complete("add uuid_getvar ::console::list_uuid");
switch_console_set_complete("add uuid_hold ::console::list_uuid");
switch_console_set_complete("add uuid_hold off ::console::list_uuid");
switch_console_set_complete("add uuid_hold toggle ::console::list_uuid");
switch_console_set_complete("add uuid_send_info ::console::list_uuid");
switch_console_set_complete("add uuid_jitterbuffer ::console::list_uuid");
switch_console_set_complete("add uuid_kill ::console::list_uuid");
+31 -8
View File
@@ -1530,6 +1530,16 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_hold(switch_core_session_t *session,
const char *other_uuid;
switch_event_t *event;
if (channel) {
switch_channel_callstate_t callstate;
callstate = switch_channel_get_callstate(channel);
if (callstate == CCS_HELD) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Call is already on hold. No need to hold again.\n");
return SWITCH_STATUS_FALSE;
}
}
msg.message_id = SWITCH_MESSAGE_INDICATE_HOLD;
msg.string_arg = message;
msg.from = __FILE__;
@@ -1557,13 +1567,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_hold(switch_core_session_t *session,
SWITCH_DECLARE(switch_status_t) switch_ivr_hold_uuid(const char *uuid, const char *message, switch_bool_t moh)
{
switch_core_session_t *session;
switch_status_t status = SWITCH_STATUS_SUCCESS;
if ((session = switch_core_session_locate(uuid))) {
switch_ivr_hold(session, message, moh);
status = switch_ivr_hold(session, message, moh);
switch_core_session_rwunlock(session);
}
return SWITCH_STATUS_SUCCESS;
return status;
}
SWITCH_DECLARE(switch_status_t) switch_ivr_hold_toggle_uuid(const char *uuid, const char *message, switch_bool_t moh)
@@ -1571,21 +1582,22 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_hold_toggle_uuid(const char *uuid, co
switch_core_session_t *session;
switch_channel_t *channel;
switch_channel_callstate_t callstate;
switch_status_t status = SWITCH_STATUS_SUCCESS;
if ((session = switch_core_session_locate(uuid))) {
if ((channel = switch_core_session_get_channel(session))) {
callstate = switch_channel_get_callstate(channel);
if (callstate == CCS_ACTIVE) {
switch_ivr_hold(session, message, moh);
if (callstate == CCS_ACTIVE || callstate == CCS_UNHELD) {
status = switch_ivr_hold(session, message, moh);
} else if (callstate == CCS_HELD) {
switch_ivr_unhold(session);
status = switch_ivr_unhold(session);
}
}
switch_core_session_rwunlock(session);
}
return SWITCH_STATUS_SUCCESS;
return status;
}
SWITCH_DECLARE(switch_status_t) switch_ivr_unhold(switch_core_session_t *session)
@@ -1596,6 +1608,16 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_unhold(switch_core_session_t *session
switch_core_session_t *b_session;
switch_event_t *event;
if (channel) {
switch_channel_callstate_t callstate;
callstate = switch_channel_get_callstate(channel);
if (callstate != CCS_HELD) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Call is not on hold. No need to unhold.\n");
return SWITCH_STATUS_FALSE;
}
}
msg.message_id = SWITCH_MESSAGE_INDICATE_UNHOLD;
msg.from = __FILE__;
@@ -1624,13 +1646,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_unhold(switch_core_session_t *session
SWITCH_DECLARE(switch_status_t) switch_ivr_unhold_uuid(const char *uuid)
{
switch_core_session_t *session;
switch_status_t status = SWITCH_STATUS_SUCCESS;
if ((session = switch_core_session_locate(uuid))) {
switch_ivr_unhold(session);
status = switch_ivr_unhold(session);
switch_core_session_rwunlock(session);
}
return SWITCH_STATUS_SUCCESS;
return status;
}