From 2890afc9184b142c931a98fff267d408e807b862 Mon Sep 17 00:00:00 2001 From: Dave Olszewski Date: Mon, 9 Feb 2015 18:03:56 -0800 Subject: [PATCH] FS-7285 allow eavesdrop to bridge only one leg Add channel variables eavesdrop_bridge_aleg and eavesdrop_bridge_bleg, and if one is set to true on the eavesdrop channel, bridge that leg from the target. If neither is specified, bridge both. --- src/include/switch_types.h | 4 +++- src/mod/applications/mod_dptools/mod_dptools.c | 10 ++++++++++ src/switch_ivr_async.c | 16 ++++++++++++++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 6cd4836846..e0d11ca934 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -331,7 +331,9 @@ typedef enum { ED_MUX_READ = (1 << 0), ED_MUX_WRITE = (1 << 1), ED_DTMF = (1 << 2), - ED_COPY_DISPLAY = (1 << 3) + ED_COPY_DISPLAY = (1 << 3), + ED_BRIDGE_READ = (1 << 4), + ED_BRIDGE_WRITE = (1 << 5) } switch_eavesdrop_flag_enum_t; typedef uint32_t switch_eavesdrop_flag_t; diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index fc515a50e0..d7eb90b417 100644 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -818,11 +818,21 @@ SWITCH_STANDARD_APP(eavesdrop_function) switch_channel_t *channel = switch_core_session_get_channel(session); const char *require_group = switch_channel_get_variable(channel, "eavesdrop_require_group"); const char *enable_dtmf = switch_channel_get_variable(channel, "eavesdrop_enable_dtmf"); + const char *bridge_aleg = switch_channel_get_variable(channel, "eavesdrop_bridge_aleg"); + const char *bridge_bleg = switch_channel_get_variable(channel, "eavesdrop_bridge_bleg"); if (enable_dtmf) { flags = switch_true(enable_dtmf) ? ED_DTMF : ED_NONE; } + /* Defaults to both, if neither is set */ + if (switch_true(bridge_aleg)) { + flags |= ED_BRIDGE_READ; + } + if (switch_true(bridge_bleg)) { + flags |= ED_BRIDGE_WRITE; + } + if (!strcasecmp((char *) data, "all")) { switch_cache_db_handle_t *db = NULL; char *errmsg = NULL; diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index 0b58c11433..2755d90a4b 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -1758,6 +1758,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session char cid_buf[1024] = ""; switch_caller_profile_t *cp = NULL; uint32_t sanity = 600; + switch_media_bug_flag_t read_flags = 0, write_flags = 0; if (!switch_channel_media_up(channel)) { goto end; @@ -1847,6 +1848,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session write_frame.buflen = sizeof(buf); write_frame.rate = codec.implementation->actual_samples_per_second; + /* Make sure that at least one leg is bridged, default to both */ + if (! (flags & (ED_BRIDGE_READ | ED_BRIDGE_WRITE))) { + flags |= ED_BRIDGE_READ | ED_BRIDGE_WRITE; + } + ep->eavesdropper = session; ep->flags = flags; switch_mutex_init(&ep->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(tsession)); @@ -1862,10 +1868,16 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session switch_buffer_add_mutex(ep->r_buffer, ep->r_mutex); + if (flags & ED_BRIDGE_READ) { + read_flags = SMBF_READ_STREAM | SMBF_READ_REPLACE; + } + if (flags & ED_BRIDGE_WRITE) { + write_flags = SMBF_WRITE_STREAM | SMBF_WRITE_REPLACE; + } + if (switch_core_media_bug_add(tsession, "eavesdrop", uuid, eavesdrop_callback, ep, 0, - SMBF_READ_STREAM | SMBF_WRITE_STREAM | SMBF_READ_REPLACE | SMBF_WRITE_REPLACE | - SMBF_READ_PING | SMBF_THREAD_LOCK | SMBF_NO_PAUSE, + read_flags | write_flags | SMBF_READ_PING | SMBF_THREAD_LOCK | SMBF_NO_PAUSE, &bug) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot attach bug\n"); goto end;