diff --git a/src/include/switch_types.h b/src/include/switch_types.h index edd630ffcb..477aa3b877 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -887,6 +887,7 @@ typedef enum { SWITCH_MESSAGE_INDICATE_SIGNAL_DATA, SWITCH_MESSAGE_INDICATE_INFO, SWITCH_MESSAGE_INDICATE_AUDIO_DATA, + SWITCH_MESSAGE_INDICATE_BLIND_TRANSFER_RESPONSE, SWITCH_MESSAGE_INVALID } switch_core_session_message_types_t; @@ -1216,6 +1217,7 @@ typedef enum { CF_ZRTP_PASS, CF_CHANNEL_SWAP, CF_PICKUP, + CF_CONFIRM_BLIND_TRANSFER, /* WARNING: DO NOT ADD ANY FLAGS BELOW THIS LINE */ /* IF YOU ADD NEW ONES CHECK IF THEY SHOULD PERSIST OR ZERO THEM IN switch_core_session.c switch_core_session_request_xml() */ CF_FLAG_MAX diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index 7005a701c5..8ae6e6f221 100755 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -4462,6 +4462,34 @@ static char *file_string_supported_formats[SWITCH_MAX_CODECS] = { 0 }; /* /FILE STRING INTERFACE */ +SWITCH_STANDARD_APP(blind_transfer_ack_function) +{ + switch_channel_t *channel = switch_core_session_get_channel(session); + switch_bool_t val = 0; + + if (data) { + val = switch_true((char *) val); + } + + if (switch_channel_test_flag(channel, CF_CONFIRM_BLIND_TRANSFER)) { + switch_core_session_t *other_session; + const char *uuid = switch_channel_get_variable(channel, "blind_transfer_uuid"); + + switch_channel_clear_flag(channel, CF_CONFIRM_BLIND_TRANSFER); + + if (!zstr(uuid) && (other_session = switch_core_session_locate(uuid))) { + switch_core_session_message_t msg = { 0 }; + msg.message_id = SWITCH_MESSAGE_INDICATE_BLIND_TRANSFER_RESPONSE; + msg.from = __FILE__; + msg.numeric_arg = val; + switch_core_session_receive_message(other_session, &msg); + switch_core_session_rwunlock(other_session); + } + } +} + + + #define SPEAK_DESC "Speak text to a channel via the tts interface" #define DISPLACE_DESC "Displace audio from a file to the channels input" @@ -4541,6 +4569,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load) SWITCH_ADD_API(api_interface, "strftime", "strftime", strftime_api_function, ""); SWITCH_ADD_API(api_interface, "presence", "presence", presence_api_function, PRESENCE_USAGE); + SWITCH_ADD_APP(app_interface, "blind_transfer_ack", "", "", blind_transfer_ack_function, "[true|false]", SAF_NONE); + SWITCH_ADD_APP(app_interface, "bind_digit_action", "bind a key sequence or regex to an action", "bind a key sequence or regex to an action", bind_digit_action_function, BIND_DIGIT_ACTION_USAGE, SAF_SUPPORT_NOMEDIA); diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index a71dc4c714..620030164c 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -1653,6 +1653,28 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi } } goto end; + case SWITCH_MESSAGE_INDICATE_BLIND_TRANSFER_RESPONSE: + { + const char *event = switch_channel_get_variable(channel, "sip_blind_transfer_event"); + const char *uuid = switch_channel_get_variable(channel, "blind_transfer_uuid"); + char *xdest; + + if (event && uuid) { + nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag;version=2.0"), + NUTAG_SUBSTATE(nua_substate_terminated), + SIPTAG_SUBSCRIPTION_STATE_STR("terminated;reason=noresource"), + SIPTAG_PAYLOAD_STR(msg->numeric_arg ? "SIP/2.0 200 OK\r\n" : "SIP/2.0 403 Forbidden\r\n"), + SIPTAG_EVENT_STR(event), TAG_END()); + + + if (!msg->numeric_arg) { + xdest = switch_core_session_sprintf(session, "intercept:%s", uuid); + switch_ivr_session_transfer(session, xdest, "inline", NULL); + } + } + + } + goto end; case SWITCH_MESSAGE_INDICATE_UNBRIDGE: if (switch_rtp_ready(tech_pvt->rtp_session)) { @@ -5343,7 +5365,6 @@ static switch_status_t list_profile_gateway(const char *line, const char *cursor return status; } - SWITCH_STANDARD_APP(sofia_sla_function) { private_object_t *tech_pvt; @@ -5502,6 +5523,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load) SWITCH_ADD_APP(app_interface, "sofia_sla", "private sofia sla function", "private sofia sla function", sofia_sla_function, "", SAF_NONE); + SWITCH_ADD_API(api_interface, "sofia", "Sofia Controls", sofia_function, " "); SWITCH_ADD_API(api_interface, "sofia_gateway_data", "Get data from a sofia gateway", sofia_gateway_data_function, " [ivar|ovar|var] "); diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index b66b29fb44..2da82ac0c2 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -264,6 +264,7 @@ typedef enum { PFLAG_PRESENCE_MAP, PFLAG_OPTIONS_RESPOND_503_ON_BUSY, PFLAG_PRESENCE_DISABLE_EARLY, + PFLAG_CONFIRM_BLIND_TRANSFER, /* No new flags below this line */ PFLAG_MAX } PFLAGS; diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 26815b6f5e..f87e8581b0 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -3105,6 +3105,12 @@ switch_status_t reconfig_sofia(sofia_profile_t *profile) } else { sofia_clear_pflag(profile, PFLAG_LOG_AUTH_FAIL); } + } else if (!strcasecmp(var, "confirm-blind-transfer")) { + if (switch_true(val)) { + sofia_set_pflag(profile, PFLAG_CONFIRM_BLIND_TRANSFER); + } else { + sofia_clear_pflag(profile, PFLAG_CONFIRM_BLIND_TRANSFER); + } } else if (!strcasecmp(var, "presence-proto-lookup")) { if (switch_true(val)) { sofia_set_pflag(profile, PFLAG_PRESENCE_MAP); @@ -3892,6 +3898,12 @@ switch_status_t config_sofia(int reload, char *profile_name) } else { sofia_clear_pflag(profile, PFLAG_LOG_AUTH_FAIL); } + } else if (!strcasecmp(var, "confirm-blind-transfer")) { + if (switch_true(val)) { + sofia_set_pflag(profile, PFLAG_CONFIRM_BLIND_TRANSFER); + } else { + sofia_clear_pflag(profile, PFLAG_CONFIRM_BLIND_TRANSFER); + } } else if (!strcasecmp(var, "presence-proto-lookup")) { if (switch_true(val)) { sofia_set_pflag(profile, PFLAG_PRESENCE_MAP); @@ -7093,37 +7105,54 @@ void sofia_handle_sip_i_refer(nua_t *nua, sofia_profile_t *profile, nua_handle_t if (exten) { switch_channel_t *channel = switch_core_session_get_channel(session); const char *br; + switch_core_session_t *b_session; - if ((br = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) { - switch_core_session_t *b_session; + if ((br = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE)) && (b_session = switch_core_session_locate(br))) { - if ((b_session = switch_core_session_locate(br))) { - switch_channel_t *b_channel = switch_core_session_get_channel(b_session); - switch_channel_set_variable(channel, "transfer_fallback_extension", from->a_user); - if (!zstr(full_ref_by)) { - switch_channel_set_variable(b_channel, SOFIA_SIP_HEADER_PREFIX "Referred-By", full_ref_by); - } - if (!zstr(full_ref_to)) { - switch_channel_set_variable(b_channel, SOFIA_REFER_TO_VARIABLE, full_ref_to); - } + const char *var; + switch_channel_t *b_channel = switch_core_session_get_channel(b_session); - if (switch_true(switch_channel_get_variable(channel, "recording_follow_transfer"))) { - switch_core_media_bug_transfer_recordings(session, b_session); - } + switch_channel_set_variable(channel, "transfer_fallback_extension", from->a_user); + if (!zstr(full_ref_by)) { + switch_channel_set_variable(b_channel, SOFIA_SIP_HEADER_PREFIX "Referred-By", full_ref_by); + } - switch_ivr_session_transfer(b_session, exten, NULL, NULL); - switch_core_session_rwunlock(b_session); + if (!zstr(full_ref_to)) { + switch_channel_set_variable(b_channel, SOFIA_REFER_TO_VARIABLE, full_ref_to); + } + + if (switch_true(switch_channel_get_variable(channel, "recording_follow_transfer"))) { + switch_core_media_bug_transfer_recordings(session, b_session); } switch_channel_set_variable(channel, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "BLIND_TRANSFER"); - nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag;version=2.0"), - NUTAG_SUBSTATE(nua_substate_terminated),SIPTAG_SUBSCRIPTION_STATE_STR("terminated;reason=noresource"), SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK\r\n"), SIPTAG_EVENT_STR(etmp), TAG_END()); + + if (((var = switch_channel_get_variable(channel, "confirm_blind_transfer")) && switch_true(var)) || + sofia_test_pflag(profile, PFLAG_CONFIRM_BLIND_TRANSFER)) { + switch_channel_set_state_flag(b_channel, CF_CONFIRM_BLIND_TRANSFER); + switch_channel_set_variable(channel, "sip_blind_transfer_event", etmp); + switch_channel_set_variable(b_channel, "blind_transfer_uuid", switch_core_session_get_uuid(session)); + switch_channel_set_variable(channel, "blind_transfer_uuid", switch_core_session_get_uuid(b_session)); + + switch_channel_set_variable(channel, "park_timeout", "600:blind_transfer"); + switch_channel_set_state(channel, CS_PARK); + } else { + nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag;version=2.0"), + NUTAG_SUBSTATE(nua_substate_terminated), + SIPTAG_SUBSCRIPTION_STATE_STR("terminated;reason=noresource"), + SIPTAG_PAYLOAD_STR("SIP/2.0 200 OK\r\n"), SIPTAG_EVENT_STR(etmp), TAG_END()); + } + + switch_ivr_session_transfer(b_session, exten, NULL, NULL); + switch_core_session_rwunlock(b_session); } else { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot Blind Transfer 1 Legged calls\n"); switch_channel_set_variable(channel_a, SWITCH_ENDPOINT_DISPOSITION_VARIABLE, "ATTENDED_TRANSFER_ERROR"); nua_notify(tech_pvt->nh, NUTAG_NEWSUB(1), SIPTAG_CONTENT_TYPE_STR("message/sipfrag;version=2.0"), - NUTAG_SUBSTATE(nua_substate_terminated),SIPTAG_SUBSCRIPTION_STATE_STR("terminated;reason=noresource"), SIPTAG_PAYLOAD_STR("SIP/2.0 403 Forbidden\r\n"), SIPTAG_EVENT_STR(etmp), TAG_END()); + NUTAG_SUBSTATE(nua_substate_terminated), + SIPTAG_SUBSCRIPTION_STATE_STR("terminated;reason=noresource"), + SIPTAG_PAYLOAD_STR("SIP/2.0 403 Forbidden\r\n"), SIPTAG_EVENT_STR(etmp), TAG_END()); } } diff --git a/src/switch_core_session.c b/src/switch_core_session.c index 6551158522..56c6e0b3a4 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -640,6 +640,7 @@ static const char *message_names[] = { "SIGNAL_DATA", "INFO", "AUDIO_DATA", + "BLIND_TRANSFER_RESPONSE", "INVALID" }; @@ -722,6 +723,24 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_perform_receive_message(swit break; } } + + + if (message->message_id == SWITCH_MESSAGE_INDICATE_BRIDGE && + switch_channel_test_flag(session->channel, CF_CONFIRM_BLIND_TRANSFER)) { + switch_core_session_t *other_session; + const char *uuid = switch_channel_get_variable(session->channel, "blind_transfer_uuid"); + + switch_channel_clear_flag(session->channel, CF_CONFIRM_BLIND_TRANSFER); + + if (!zstr(uuid) && (other_session = switch_core_session_locate(uuid))) { + switch_core_session_message_t msg = { 0 }; + msg.message_id = SWITCH_MESSAGE_INDICATE_BLIND_TRANSFER_RESPONSE; + msg.from = __FILE__; + msg.numeric_arg = 1; + switch_core_session_receive_message(other_session, &msg); + switch_core_session_rwunlock(other_session); + } + } } diff --git a/src/switch_core_state_machine.c b/src/switch_core_state_machine.c index 7b2e900e7f..61fa9290e5 100644 --- a/src/switch_core_state_machine.c +++ b/src/switch_core_state_machine.c @@ -188,6 +188,7 @@ static void switch_core_standard_on_routing(switch_core_session_t *session) static void switch_core_standard_on_execute(switch_core_session_t *session) { switch_caller_extension_t *extension; + const char *uuid; switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Standard EXECUTE\n", switch_channel_get_name(session->channel)); @@ -222,6 +223,25 @@ static void switch_core_standard_on_execute(switch_core_session_t *session) } + if (switch_channel_ready(session->channel) && switch_channel_get_state(session->channel) == CS_EXECUTE && + switch_channel_test_flag(session->channel, CF_CONFIRM_BLIND_TRANSFER) && + (uuid = switch_channel_get_variable(session->channel, "blind_transfer_uuid"))) { + switch_core_session_t *other_session; + + if ((other_session = switch_core_session_locate(uuid))) { + switch_core_session_message_t msg = { 0 }; + msg.message_id = SWITCH_MESSAGE_INDICATE_BLIND_TRANSFER_RESPONSE; + msg.from = __FILE__; + msg.numeric_arg = 0; + switch_core_session_receive_message(other_session, &msg); + switch_core_session_rwunlock(other_session); + + switch_channel_set_variable(session->channel, "park_timeout", "10:blind_transfer"); + switch_channel_set_state(session->channel, CS_PARK); + switch_channel_clear_flag(session->channel, CF_CONFIRM_BLIND_TRANSFER); + } + } + if (switch_channel_ready(session->channel) && switch_channel_get_state(session->channel) == CS_EXECUTE) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_NOTICE, "%s has executed the last dialplan instruction, hanging up.\n", switch_channel_get_name(session->channel));