Skip to content

Instantly share code, notes, and snippets.

@frek818
Created January 8, 2015 00:16
Show Gist options
  • Save frek818/cab51f3ebcabaa8fa455 to your computer and use it in GitHub Desktop.
Save frek818/cab51f3ebcabaa8fa455 to your computer and use it in GitHub Desktop.
diff --git a/src/include/switch_channel.h b/src/include/switch_channel.h
index f4655a2..be4eff4 100644
--- a/src/include/switch_channel.h
+++ b/src/include/switch_channel.h
@@ -548,7 +548,7 @@ SWITCH_DECLARE(switch_size_t) switch_channel_has_dtmf(_In_ switch_channel_t *cha
\param dtmf digit
\return SWITCH_STATUS_SUCCESS if successful
*/
-SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf(_In_ switch_channel_t *channel, _In_ const switch_dtmf_t *dtmf);
+SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf(_In_ switch_channel_t *channel, _In_ switch_dtmf_t *dtmf);
SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf_string(_In_ switch_channel_t *channel, _In_ const char *dtmf_string);
/*!
diff --git a/src/include/switch_types.h b/src/include/switch_types.h
index f1c5f1b..ae6509a 100644
--- a/src/include/switch_types.h
+++ b/src/include/switch_types.h
@@ -138,6 +138,7 @@ SWITCH_BEGIN_EXTERN_C
#define SWITCH_PROTO_SPECIFIC_HANGUP_CAUSE_VARIABLE "proto_specific_hangup_cause"
#define SWITCH_TRANSFER_HISTORY_VARIABLE "transfer_history"
#define SWITCH_TRANSFER_SOURCE_VARIABLE "transfer_source"
+#define SWITCH_SENSITIVE_DTMF_VARIABLE "sensitive_dtmf"
#define SWITCH_CHANNEL_EXECUTE_ON_ANSWER_VARIABLE "execute_on_answer"
#define SWITCH_CHANNEL_EXECUTE_ON_PRE_ANSWER_VARIABLE "execute_on_pre_answer"
@@ -243,7 +244,8 @@ typedef enum {
typedef enum {
- DTMF_FLAG_SKIP_PROCESS = (1 << 0)
+ DTMF_FLAG_SKIP_PROCESS = (1 << 0),
+ DTMF_FLAG_SENSITIVE = (1 << 1)
} dtmf_flag_t;
typedef struct {
diff --git a/src/switch_channel.c b/src/switch_channel.c
index 6e4c607..379fdcf 100644
--- a/src/switch_channel.c
+++ b/src/switch_channel.c
@@ -372,14 +372,19 @@ SWITCH_DECLARE(switch_size_t) switch_channel_has_dtmf(switch_channel_t *channel)
return has;
}
-SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf(switch_channel_t *channel, const switch_dtmf_t *dtmf)
+SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf(switch_channel_t *channel, switch_dtmf_t *dtmf)
{
switch_status_t status;
void *pop;
switch_dtmf_t new_dtmf = { 0 };
+ switch_bool_t sensitive = switch_true(switch_channel_get_variable(channel, SWITCH_SENSITIVE_DTMF_VARIABLE));
switch_assert(dtmf);
+ if (sensitive) {
+ switch_set_flag(dtmf, DTMF_FLAG_SENSITIVE);
+ }
+
switch_mutex_lock(channel->dtmf_mutex);
new_dtmf = *dtmf;
@@ -390,18 +395,19 @@ SWITCH_DECLARE(switch_status_t) switch_channel_queue_dtmf(switch_channel_t *chan
if (is_dtmf(new_dtmf.digit)) {
switch_dtmf_t *dt;
int x = 0;
- char str[2] = "";
- str[0] = new_dtmf.digit;
+ if (!sensitive) {
+ switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "RECV DTMF %c:%d\n", new_dtmf.digit, new_dtmf.duration);
+ }
if (new_dtmf.digit != 'w' && new_dtmf.digit != 'W') {
if (new_dtmf.duration > switch_core_max_dtmf_duration(0)) {
- switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG1, "%s EXCESSIVE DTMF DIGIT [%s] LEN [%d]\n",
- switch_channel_get_name(channel), str, new_dtmf.duration);
+ switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "%s EXCESSIVE DTMF DIGIT LEN [%d]\n",
+ switch_channel_get_name(channel), new_dtmf.duration);
new_dtmf.duration = switch_core_max_dtmf_duration(0);
} else if (new_dtmf.duration < switch_core_min_dtmf_duration(0)) {
- switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG1, "%s SHORT DTMF DIGIT [%s] LEN [%d]\n",
- switch_channel_get_name(channel), str, new_dtmf.duration);
+ switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "%s SHORT DTMF DIGIT LEN [%d]\n",
+ switch_channel_get_name(channel), new_dtmf.duration);
new_dtmf.duration = switch_core_min_dtmf_duration(0);
}
}
@@ -502,14 +508,16 @@ SWITCH_DECLARE(switch_status_t) switch_channel_dequeue_dtmf(switch_channel_t *ch
void *pop;
switch_dtmf_t *dt;
switch_status_t status = SWITCH_STATUS_FALSE;
+ int sensitive = 0;
switch_mutex_lock(channel->dtmf_mutex);
if (switch_queue_trypop(channel->dtmf_queue, &pop) == SWITCH_STATUS_SUCCESS) {
dt = (switch_dtmf_t *) pop;
*dtmf = *dt;
+ sensitive = switch_test_flag(dtmf, DTMF_FLAG_SENSITIVE);
- if (switch_queue_trypush(channel->dtmf_log_queue, dt) != SWITCH_STATUS_SUCCESS) {
+ if (!sensitive && switch_queue_trypush(channel->dtmf_log_queue, dt) != SWITCH_STATUS_SUCCESS) {
free(dt);
}
@@ -517,11 +525,11 @@ SWITCH_DECLARE(switch_status_t) switch_channel_dequeue_dtmf(switch_channel_t *ch
if (dtmf->duration > switch_core_max_dtmf_duration(0)) {
switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_WARNING, "%s EXCESSIVE DTMF DIGIT [%c] LEN [%d]\n",
- switch_channel_get_name(channel), dtmf->digit, dtmf->duration);
+ switch_channel_get_name(channel), sensitive ? 'S' : dtmf->digit, dtmf->duration);
dtmf->duration = switch_core_max_dtmf_duration(0);
} else if (dtmf->duration < switch_core_min_dtmf_duration(0)) {
switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_WARNING, "%s SHORT DTMF DIGIT [%c] LEN [%d]\n",
- switch_channel_get_name(channel), dtmf->digit, dtmf->duration);
+ switch_channel_get_name(channel), sensitive ? 'S' : dtmf->digit, dtmf->duration);
dtmf->duration = switch_core_min_dtmf_duration(0);
} else if (!dtmf->duration) {
dtmf->duration = switch_core_default_dtmf_duration(0);
@@ -531,7 +539,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_dequeue_dtmf(switch_channel_t *ch
}
switch_mutex_unlock(channel->dtmf_mutex);
- if (status == SWITCH_STATUS_SUCCESS && switch_event_create(&event, SWITCH_EVENT_DTMF) == SWITCH_STATUS_SUCCESS) {
+ if (!sensitive && status == SWITCH_STATUS_SUCCESS && switch_event_create(&event, SWITCH_EVENT_DTMF) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(channel, event);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "DTMF-Digit", "%c", dtmf->digit);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "DTMF-Duration", "%u", dtmf->duration);
diff --git a/src/switch_core_io.c b/src/switch_core_io.c
index 7b9580c..aae42d4 100644
--- a/src/switch_core_io.c
+++ b/src/switch_core_io.c
@@ -1360,6 +1360,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_recv_dtmf(switch_core_sessio
return SWITCH_STATUS_FALSE;
}
+ if (switch_test_flag(dtmf, DTMF_FLAG_SENSITIVE)) {
+ return SWITCH_STATUS_SUCCESS;
+ }
+
switch_assert(dtmf);
new_dtmf = *dtmf;
@@ -1403,6 +1407,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_send_dtmf(switch_core_sessio
return SWITCH_STATUS_FALSE;
}
+ if (switch_test_flag(dtmf, DTMF_FLAG_SENSITIVE)) {
+ return SWITCH_STATUS_SUCCESS;
+ }
+
switch_assert(dtmf);
new_dtmf = *dtmf;
diff --git a/src/switch_ivr_play_say.c b/src/switch_ivr_play_say.c
index c15da6f..2e272c9 100644
--- a/src/switch_ivr_play_say.c
+++ b/src/switch_ivr_play_say.c
@@ -2031,7 +2031,7 @@ SWITCH_DECLARE(switch_status_t) switch_play_and_get_digits(switch_core_session_t
if (zstr(digits_regex)) {
return SWITCH_STATUS_SUCCESS;
}
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Test Regex [%s][%s]\n", digit_buffer, digits_regex);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "Test Regex [%s][%s]\n", digit_buffer, digits_regex);
if (switch_regex_match(digit_buffer, digits_regex) == SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_SUCCESS;
} else {
diff --git a/src/switch_rtp.c b/src/switch_rtp.c
index ab7bc29..078cca1 100644
--- a/src/switch_rtp.c
+++ b/src/switch_rtp.c
@@ -3792,10 +3792,8 @@ SWITCH_DECLARE(switch_size_t) switch_rtp_dequeue_dtmf(switch_rtp_t *rtp_session,
switch_mutex_lock(rtp_session->dtmf_data.dtmf_mutex);
if (switch_queue_trypop(rtp_session->dtmf_data.dtmf_inqueue, &pop) == SWITCH_STATUS_SUCCESS) {
- switch_core_session_t *session = switch_core_memory_pool_get_data(rtp_session->pool, "__session");
_dtmf = (switch_dtmf_t *) pop;
*dtmf = *_dtmf;
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "RTP RECV DTMF %c:%d\n", dtmf->digit, dtmf->duration);
bytes++;
free(pop);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment