diff --git a/src/include/switch_ivr.h b/src/include/switch_ivr.h index 3affb6c0ad..40ba1dc16f 100644 --- a/src/include/switch_ivr.h +++ b/src/include/switch_ivr.h @@ -806,6 +806,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_read(switch_core_session_t *session, const char *var_name, char *digit_buffer, switch_size_t digit_buffer_length, uint32_t timeout, const char *valid_terminators); +SWITCH_DECLARE(switch_status_t) switch_ivr_block_dtmf_session(switch_core_session_t *session); +SWITCH_DECLARE(switch_status_t) switch_ivr_unblock_dtmf_session(switch_core_session_t *session); + SWITCH_DECLARE(switch_status_t) switch_ivr_bind_dtmf_meta_session(switch_core_session_t *session, uint32_t key, switch_bind_flag_t bind_flags, const char *app); SWITCH_DECLARE(switch_status_t) switch_ivr_unbind_dtmf_meta_session(switch_core_session_t *session, uint32_t key); diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index 7ca52419f0..d6020f1314 100755 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -198,6 +198,16 @@ SWITCH_STANDARD_APP(soft_hold_function) } } +SWITCH_STANDARD_APP(dtmf_unblock_function) +{ + switch_ivr_unblock_dtmf_session(session); +} + +SWITCH_STANDARD_APP(dtmf_block_function) +{ + switch_ivr_block_dtmf_session(session); +} + #define UNBIND_SYNTAX "[]" SWITCH_STANDARD_APP(dtmf_unbind_function) { @@ -3108,6 +3118,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load) SAF_SUPPORT_NOMEDIA); SWITCH_ADD_APP(app_interface, "unbind_meta_app", "Unbind a key from an application", "Unbind a key from an application", dtmf_unbind_function, UNBIND_SYNTAX, SAF_SUPPORT_NOMEDIA); + SWITCH_ADD_APP(app_interface, "block_dfmf", "Block DTMF", "Block DTMF", dtmf_block_function, "", SAF_SUPPORT_NOMEDIA); + SWITCH_ADD_APP(app_interface, "unblock_dtmf", "Stop blocking DTMF", "Stop blocking DTMF", dtmf_unblock_function, "", SAF_SUPPORT_NOMEDIA); SWITCH_ADD_APP(app_interface, "intercept", "intercept", "intercept", intercept_function, INTERCEPT_SYNTAX, SAF_NONE); SWITCH_ADD_APP(app_interface, "eavesdrop", "eavesdrop on a uuid", "eavesdrop on a uuid", eavesdrop_function, eavesdrop_SYNTAX, SAF_MEDIA_TAP); SWITCH_ADD_APP(app_interface, "three_way", "three way call with a uuid", "three way call with a uuid", three_way_function, threeway_SYNTAX, diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index 1ad5c3a6fa..9b70335536 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -2180,6 +2180,7 @@ typedef struct { } dtmf_meta_data_t; #define SWITCH_META_VAR_KEY "__dtmf_meta" +#define SWITCH_BLOCK_DTMF_KEY "__dtmf_block" typedef struct { switch_core_session_t *session; @@ -2355,6 +2356,44 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_unbind_dtmf_meta_session(switch_core_ return SWITCH_STATUS_SUCCESS; } +static switch_status_t block_on_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf, switch_dtmf_direction_t direction) +{ + switch_channel_t *channel = switch_core_session_get_channel(session); + uint8_t enabled = (intptr_t)switch_channel_get_private(channel, SWITCH_BLOCK_DTMF_KEY); + + if (!enabled || switch_channel_test_flag(channel, CF_INNER_BRIDGE)) { + return SWITCH_STATUS_SUCCESS; + } + + return SWITCH_STATUS_FALSE; +} + +SWITCH_DECLARE(switch_status_t) switch_ivr_unblock_dtmf_session(switch_core_session_t *session) +{ + switch_channel_t *channel = switch_core_session_get_channel(session); + uint8_t enabled = (intptr_t)switch_channel_get_private(channel, SWITCH_BLOCK_DTMF_KEY); + + if (enabled) { + switch_channel_set_private(channel, SWITCH_BLOCK_DTMF_KEY, NULL); + } + + return SWITCH_STATUS_SUCCESS; +} + +SWITCH_DECLARE(switch_status_t) switch_ivr_block_dtmf_session(switch_core_session_t *session) +{ + switch_channel_t *channel = switch_core_session_get_channel(session); + uint8_t enabled = (intptr_t)switch_channel_get_private(channel, SWITCH_BLOCK_DTMF_KEY); + + if (!enabled) { + switch_channel_set_private(channel, SWITCH_BLOCK_DTMF_KEY, (void *)(intptr_t)1); + switch_core_event_hook_add_send_dtmf(session, block_on_dtmf); + switch_core_event_hook_add_recv_dtmf(session, block_on_dtmf); + } + + return SWITCH_STATUS_SUCCESS; +} + SWITCH_DECLARE(switch_status_t) switch_ivr_bind_dtmf_meta_session(switch_core_session_t *session, uint32_t key, switch_bind_flag_t bind_flags, const char *app) {