From d1ad4d477c62bc8984b38b52a2b92f54e1943bcd Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 31 Oct 2012 12:56:09 -0500 Subject: [PATCH] add no_loopback flag to apps so they can tell mod_loopback to bow out --- src/include/switch_types.h | 3 +- .../applications/mod_spandsp/mod_spandsp.c | 4 +- src/mod/endpoints/mod_loopback/mod_loopback.c | 40 +++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/include/switch_types.h b/src/include/switch_types.h index 7138b13293..d7d96b5aaf 100644 --- a/src/include/switch_types.h +++ b/src/include/switch_types.h @@ -1304,7 +1304,8 @@ typedef enum { SAF_SUPPORT_NOMEDIA = (1 << 0), SAF_ROUTING_EXEC = (1 << 1), SAF_MEDIA_TAP = (1 << 2), - SAF_ZOMBIE_EXEC = (1 << 3) + SAF_ZOMBIE_EXEC = (1 << 3), + SAF_NO_LOOPBACK = (1 << 4) } switch_application_flag_enum_t; typedef uint32_t switch_application_flag_t; diff --git a/src/mod/applications/mod_spandsp/mod_spandsp.c b/src/mod/applications/mod_spandsp/mod_spandsp.c index 6ee395770f..fa7a0da79a 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp.c +++ b/src/mod/applications/mod_spandsp/mod_spandsp.c @@ -714,9 +714,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_spandsp_init) t38_gateway_function, "", SAF_MEDIA_TAP); SWITCH_ADD_APP(app_interface, "rxfax", "FAX Receive Application", "FAX Receive Application", spanfax_rx_function, SPANFAX_RX_USAGE, - SAF_SUPPORT_NOMEDIA); + SAF_SUPPORT_NOMEDIA | SAF_NO_LOOPBACK); SWITCH_ADD_APP(app_interface, "txfax", "FAX Transmit Application", "FAX Transmit Application", spanfax_tx_function, SPANFAX_TX_USAGE, - SAF_SUPPORT_NOMEDIA); + SAF_SUPPORT_NOMEDIA | SAF_NO_LOOPBACK); SWITCH_ADD_APP(app_interface, "spandsp_stop_dtmf", "stop inband dtmf", "Stop detecting inband dtmf.", stop_dtmf_session_function, "", SAF_NONE); SWITCH_ADD_APP(app_interface, "spandsp_start_dtmf", "Detect dtmf", "Detect inband dtmf on the session", dtmf_session_function, "", SAF_MEDIA_TAP); diff --git a/src/mod/endpoints/mod_loopback/mod_loopback.c b/src/mod/endpoints/mod_loopback/mod_loopback.c index 8835cc05a1..adf911cbba 100644 --- a/src/mod/endpoints/mod_loopback/mod_loopback.c +++ b/src/mod/endpoints/mod_loopback/mod_loopback.c @@ -42,6 +42,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_loopback_load); SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_loopback_shutdown); SWITCH_MODULE_DEFINITION(mod_loopback, mod_loopback_load, mod_loopback_shutdown, NULL); +static switch_status_t find_non_loopback_bridge(switch_core_session_t *session, switch_core_session_t **br_session, const char **br_uuid); + static switch_endpoint_interface_t *loopback_endpoint_interface = NULL; typedef enum { @@ -409,6 +411,8 @@ static switch_status_t channel_on_execute(switch_core_session_t *session) { switch_channel_t *channel = NULL; private_t *tech_pvt = NULL; + switch_caller_extension_t *exten; + int bow = 0; channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -418,6 +422,37 @@ static switch_status_t channel_on_execute(switch_core_session_t *session) switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s CHANNEL EXECUTE\n", switch_channel_get_name(channel)); + + if ((exten = switch_channel_get_caller_extension(channel))) { + switch_caller_application_t *app_p; + + for (app_p = exten->applications; app_p; app_p = app_p->next) { + int32_t flags; + + switch_core_session_get_app_flags(app_p->application_name, &flags); + + if ((flags & SAF_NO_LOOPBACK)) { + bow = 1; + break; + } + } + } + + if (bow) { + switch_core_session_t *other_session; + const char *other_uuid; + + if ((find_non_loopback_bridge(tech_pvt->other_session, &other_session, &other_uuid) == SWITCH_STATUS_SUCCESS)) { + switch_caller_extension_t *extension; + switch_channel_t *other_channel = switch_core_session_get_channel(other_session); + switch_caller_extension_clone(&extension, exten, switch_core_session_get_pool(other_session)); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_INFO, "BOWOUT Transfering current extension to non-loopback leg.\n"); + switch_channel_transfer_to_extension(other_channel, extension); + switch_core_session_rwunlock(other_session); + } + + } + return SWITCH_STATUS_SUCCESS; } @@ -1126,11 +1161,16 @@ static switch_io_routines_t channel_io_routines = { /*.receive_message */ channel_receive_message }; +SWITCH_STANDARD_APP(unloop_function) { /* NOOP */} + SWITCH_MODULE_LOAD_FUNCTION(mod_loopback_load) { + switch_application_interface_t *app_interface; memset(&globals, 0, sizeof(globals)); + SWITCH_ADD_APP(app_interface, "unloop", "Tell loopback to unfold", "Tell loopback to unfold", unloop_function, "", SAF_NO_LOOPBACK); + /* connect my internal structure to the blank pointer passed to me */ *module_interface = switch_loadable_module_create_module_interface(pool, modname); loopback_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);