]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add block_dtmf and unblock_dtmf apps
authorMichael Jerris <mike@jerris.com>
Tue, 8 Jun 2010 01:14:47 +0000 (21:14 -0400)
committerMichael Jerris <mike@jerris.com>
Tue, 8 Jun 2010 01:14:47 +0000 (21:14 -0400)
src/include/switch_ivr.h
src/mod/applications/mod_dptools/mod_dptools.c
src/switch_ivr_async.c

index 3affb6c0ade500f7bf8cbd7a8a945ba2fbd9ad45..40ba1dc16f07b1ca9da8f0596aa9f27d09f2b952 100644 (file)
@@ -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);
index 7ca52419f0767e23c095b9e97eb2e56a1856adfa..d6020f1314a764e88254d6c356cdb5f02a489c82 100755 (executable)
@@ -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 "[<key>]"
 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,
index 1ad5c3a6fa86cc9d688f2fc37c641c119a71ad0d..9b70335536f16c34efadaed794cab728209705ff 100644 (file)
@@ -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)
 {