From cd041b768c7294718e1f624dc33f6137ad63e7d4 Mon Sep 17 00:00:00 2001 From: Chris Rienzo Date: Thu, 30 Jul 2020 21:54:56 +0000 Subject: [PATCH] [mod_spandsp] Add verbose-log-level configuration. --- .../vanilla/autoload_configs/spandsp.conf.xml | 1 + .../applications/mod_spandsp/mod_spandsp.c | 6 +++ .../applications/mod_spandsp/mod_spandsp.h | 7 +++ .../mod_spandsp/mod_spandsp_dsp.c | 7 ++- .../mod_spandsp/mod_spandsp_fax.c | 44 +++++++++++++++---- 5 files changed, 55 insertions(+), 10 deletions(-) diff --git a/conf/vanilla/autoload_configs/spandsp.conf.xml b/conf/vanilla/autoload_configs/spandsp.conf.xml index 2471ca52ce..6345512908 100644 --- a/conf/vanilla/autoload_configs/spandsp.conf.xml +++ b/conf/vanilla/autoload_configs/spandsp.conf.xml @@ -28,6 +28,7 @@ + diff --git a/src/mod/applications/mod_spandsp/mod_spandsp.c b/src/mod/applications/mod_spandsp/mod_spandsp.c index 35d0cb585f..3f69b9746a 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp.c +++ b/src/mod/applications/mod_spandsp/mod_spandsp.c @@ -516,6 +516,7 @@ switch_status_t load_configuration(switch_bool_t reload) spandsp_globals.enable_tep = 0; spandsp_globals.total_sessions = 0; spandsp_globals.verbose = 0; + spandsp_globals.verbose_log_level = SWITCH_LOG_DEBUG; spandsp_globals.use_ecm = 1; spandsp_globals.disable_v17 = 0; spandsp_globals.prepend_string = switch_core_strdup(spandsp_globals.config_pool, "fax"); @@ -591,6 +592,11 @@ switch_status_t load_configuration(switch_bool_t reload) spandsp_globals.verbose = 1; else spandsp_globals.verbose = 0; + } else if (!strcmp(name, "verbose-log-level")) { + switch_log_level_t verbose_log_level = switch_log_str2level(value); + if (verbose_log_level != SWITCH_LOG_INVALID) { + spandsp_globals.verbose_log_level = verbose_log_level; + } } else if (!strcmp(name, "disable-v17")) { if (switch_true(value)) spandsp_globals.disable_v17 = 1; diff --git a/src/mod/applications/mod_spandsp/mod_spandsp.h b/src/mod/applications/mod_spandsp/mod_spandsp.h index 0863831b3c..216895dd29 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp.h +++ b/src/mod/applications/mod_spandsp/mod_spandsp.h @@ -70,6 +70,7 @@ struct spandsp_globals { short int use_ecm; short int verbose; + switch_log_level_t verbose_log_level; short int disable_v17; short int enable_tep; short int enable_colour_fax; @@ -106,6 +107,12 @@ typedef enum { FUNCTION_GW } mod_spandsp_fax_application_mode_t; +struct mod_spandsp_log_data { + switch_log_level_t verbose_log_level; + switch_core_session_t *session; +}; +typedef struct mod_spandsp_log_data mod_spandsp_log_data_t; + /****************************************************************************** * TONE DETECTION WITH CADENCE */ diff --git a/src/mod/applications/mod_spandsp/mod_spandsp_dsp.c b/src/mod/applications/mod_spandsp/mod_spandsp_dsp.c index fca74635e8..836808a48d 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp_dsp.c +++ b/src/mod/applications/mod_spandsp/mod_spandsp_dsp.c @@ -406,7 +406,12 @@ static switch_bool_t inband_dtmf_callback(switch_media_bug_t *bug, void *user_da switch (type) { case SWITCH_ABC_TYPE_INIT: { pvt->dtmf_detect = dtmf_rx_init(NULL, NULL, NULL); - span_log_set_message_handler(dtmf_rx_get_logging_state(pvt->dtmf_detect), mod_spandsp_log_message, pvt->session); + { + mod_spandsp_log_data_t *log_data = switch_core_session_alloc(pvt->session, sizeof(*log_data)); + log_data->session = pvt->session; + log_data->verbose_log_level = spandsp_globals.verbose_log_level; + span_log_set_message_handler(dtmf_rx_get_logging_state(pvt->dtmf_detect), mod_spandsp_log_message, log_data); + } if (pvt->verbose) { span_log_set_level(dtmf_rx_get_logging_state(pvt->dtmf_detect), SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); } diff --git a/src/mod/applications/mod_spandsp/mod_spandsp_fax.c b/src/mod/applications/mod_spandsp/mod_spandsp_fax.c index 1f63eb1aed..14c2bb253b 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp_fax.c +++ b/src/mod/applications/mod_spandsp/mod_spandsp_fax.c @@ -106,6 +106,7 @@ struct pvt_s { int enable_colour_to_bilevel; int enable_grayscale_to_bilevel; int verbose; + switch_log_level_t verbose_log_level; int caller; int tx_page_start; @@ -273,7 +274,9 @@ static void counter_increment(void) void mod_spandsp_log_message(void *user_data, int level, const char *msg) { int fs_log_level; - switch_core_session_t *session = (switch_core_session_t *)user_data; + mod_spandsp_log_data_t *log_data = (mod_spandsp_log_data_t *)user_data; + switch_core_session_t *session = log_data ? log_data->session : NULL; + switch_log_level_t verbose_log_level = log_data ? log_data->verbose_log_level : spandsp_globals.verbose_log_level; switch (level) { case SPAN_LOG_NONE: @@ -290,12 +293,12 @@ void mod_spandsp_log_message(void *user_data, int level, const char *msg) case SPAN_LOG_FLOW_2: case SPAN_LOG_FLOW_3: default: /* SPAN_LOG_DEBUG, SPAN_LOG_DEBUG_2, SPAN_LOG_DEBUG_3 */ - fs_log_level = SWITCH_LOG_DEBUG; + fs_log_level = verbose_log_level; break; } if (!zstr(msg)) { - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), fs_log_level, "%s", msg); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), fs_log_level, "%s", msg); } } @@ -811,8 +814,13 @@ static switch_status_t spanfax_init(pvt_t *pvt, transport_mode_t trans_mode) fax_set_transmit_on_idle(fax, TRUE); - span_log_set_message_handler(fax_get_logging_state(fax), mod_spandsp_log_message, pvt->session); - span_log_set_message_handler(t30_get_logging_state(t30), mod_spandsp_log_message, pvt->session); + { + mod_spandsp_log_data_t *log_data = switch_core_session_alloc(pvt->session, sizeof(*log_data)); + log_data->session = pvt->session; + log_data->verbose_log_level = pvt->verbose_log_level; + span_log_set_message_handler(fax_get_logging_state(fax), mod_spandsp_log_message, log_data); + span_log_set_message_handler(t30_get_logging_state(t30), mod_spandsp_log_message, log_data); + } if (pvt->verbose) { span_log_set_level(fax_get_logging_state(fax), SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); @@ -865,8 +873,13 @@ static switch_status_t spanfax_init(pvt_t *pvt, transport_mode_t trans_mode) msg.message_id = SWITCH_MESSAGE_INDICATE_UDPTL_MODE; switch_core_session_receive_message(pvt->session, &msg); - span_log_set_message_handler(t38_terminal_get_logging_state(t38), mod_spandsp_log_message, pvt->session); - span_log_set_message_handler(t30_get_logging_state(t30), mod_spandsp_log_message, pvt->session); + { + mod_spandsp_log_data_t *log_data = switch_core_session_alloc(pvt->session, sizeof(*log_data)); + log_data->session = pvt->session; + log_data->verbose_log_level = pvt->verbose_log_level; + span_log_set_message_handler(t38_terminal_get_logging_state(t38), mod_spandsp_log_message, log_data); + span_log_set_message_handler(t30_get_logging_state(t30), mod_spandsp_log_message, log_data); + } if (pvt->verbose) { span_log_set_level(t38_terminal_get_logging_state(t38), SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); @@ -922,8 +935,13 @@ static switch_status_t spanfax_init(pvt_t *pvt, transport_mode_t trans_mode) t38_gateway_set_ecm_capability(pvt->t38_gateway_state, pvt->use_ecm); switch_channel_set_variable(channel, "fax_ecm_requested", pvt->use_ecm ? "true" : "false"); - span_log_set_message_handler(t38_gateway_get_logging_state(pvt->t38_gateway_state), mod_spandsp_log_message, pvt->session); - span_log_set_message_handler(t38_core_get_logging_state(pvt->t38_core), mod_spandsp_log_message, pvt->session); + { + mod_spandsp_log_data_t *log_data = switch_core_session_alloc(pvt->session, sizeof(*log_data)); + log_data->session = pvt->session; + log_data->verbose_log_level = pvt->verbose_log_level; + span_log_set_message_handler(t38_gateway_get_logging_state(pvt->t38_gateway_state), mod_spandsp_log_message, log_data); + span_log_set_message_handler(t38_core_get_logging_state(pvt->t38_core), mod_spandsp_log_message, log_data); + } if (pvt->verbose) { span_log_set_level(t38_gateway_get_logging_state(pvt->t38_gateway_state), SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); @@ -1377,6 +1395,14 @@ static pvt_t *pvt_init(switch_core_session_t *session, mod_spandsp_fax_applicati pvt->verbose = spandsp_globals.verbose; } + pvt->verbose_log_level = spandsp_globals.verbose_log_level; + if ((tmp = switch_channel_get_variable(channel, "fax_verbose_log_level"))) { + switch_log_level_t verbose_log_level = switch_log_str2level(tmp); + if (verbose_log_level != SWITCH_LOG_INVALID) { + pvt->verbose_log_level = verbose_log_level; + } + } + if ((tmp = switch_channel_get_variable(channel, "fax_force_caller"))) { if (switch_true(tmp)) { pvt->caller = 1;