From: Mike Jerris Date: Tue, 23 Apr 2019 20:07:37 +0000 (-0600) Subject: Revert "FS-9490: [mod_sofia] add filter to SIP messages that match a regexp." X-Git-Tag: v1.10.0~136 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e7dda1b027f251d3441260f3960dd4cf91cb69a5;p=thirdparty%2Ffreeswitch.git Revert "FS-9490: [mod_sofia] add filter to SIP messages that match a regexp." This reverts commit 53dbe5d84a9c3624804a2b9259433f4d525425f8. This previous patch made logger function not reentrant so reverting until we can get a fix without that issue --- diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 9cb1816528..37d82c05b3 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -4426,10 +4426,6 @@ SWITCH_STANDARD_API(sofia_function) switch_status_t status = SWITCH_STATUS_SUCCESS; sofia_command_t func = NULL; int lead = 1; - const char *errorptr; - int erroffset; - const unsigned char *tables = 0; - uint32_t flags = 0; static const char usage_string[] = "USAGE:\n" "--------------------------------------------------------------------------------\n" "sofia global siptrace \n" @@ -4474,29 +4470,6 @@ SWITCH_STANDARD_API(sofia_function) func = cmd_xml_status; } else if (!strcasecmp(argv[0], "jsonstatus")) { func = cmd_json_status; - } else if (!strcasecmp(argv[0], "filter")) { - if (argc > 1) { - if (!strcasecmp(argv[1],"off")) { - mod_sofia_globals.filtering = SWITCH_FALSE; - switch_regex_free(mod_sofia_globals.filter_re); - } else { - mod_sofia_globals.filtering = SWITCH_TRUE; - strncpy( mod_sofia_globals.filter_expression, argv[1], sizeof(mod_sofia_globals.filter_expression) ); - mod_sofia_globals.filter_re = switch_regex_compile( argv[1], flags, &errorptr, &erroffset, tables ); - if (errorptr) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "COMPILE ERROR: %d [%s][%s]\n", erroffset, errorptr, argv[1]); - stream->write_function(stream, "Couldn't compile that regex: %s\n", argv[1]); - switch_regex_free(mod_sofia_globals.filter_re); - goto done; - } - - } - stream->write_function(stream, "+OK %s filtering sofia log for %s\n", mod_sofia_globals.filtering ? "enabled" : "disabled", mod_sofia_globals.filter_expression ); - } else { - stream->write_function(stream, "%s%s", "sofia filter is ", mod_sofia_globals.filtering ? "enabled. " : "disabled. ", mod_sofia_globals.filter_expression); - stream->write_function(stream, "%s", " (sofia filter ) - Enable, disable filtering, set 'filter-regex' to use as filter. Set 'filter-expression' to 'off' to stop filtering\n"); - } - goto done; } else if (!strcasecmp(argv[0], "tracelevel")) { if (argv[1]) { mod_sofia_globals.tracelevel = switch_log_str2level(argv[1]); @@ -6397,7 +6370,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load) switch_console_set_complete("add sofia ::[help:status"); switch_console_set_complete("add sofia status profile ::sofia::list_profiles reg"); switch_console_set_complete("add sofia status gateway ::sofia::list_gateways"); - switch_console_set_complete("add sofia filter"); + switch_console_set_complete("add sofia loglevel ::[all:default:tport:iptsec:nea:nta:nth_client:nth_server:nua:soa:sresolv:stun ::[0:1:2:3:4:5:6:7:8:9"); switch_console_set_complete("add sofia tracelevel ::[console:alert:crit:err:warning:notice:info:debug"); diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 5e5feb2d6d..901a66a3e6 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -155,12 +155,6 @@ typedef enum { SOFIA_CONFIG_RESPAWN } sofia_config_t; -typedef enum { - FILTER_UNKOWN = 0, - FILTER_BEGIN = 1, - FILTER_END = 2 -} filter_packet_state_t; - typedef struct sofia_dispatch_event_s { nua_saved_event_t event[1]; nua_handle_t *nh; @@ -411,9 +405,6 @@ struct mod_sofia_globals { uint32_t max_reg_threads; time_t presence_epoch; int presence_year; - char filter_expression[100]; - switch_regex_t *filter_re; - switch_bool_t filtering; }; extern struct mod_sofia_globals mod_sofia_globals; diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index caffb92567..f3200328b8 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -35,7 +35,6 @@ * Emmanuel Schmidbauer * William King * David Knell - * David Villasmil * * sofia.c -- SOFIA SIP Endpoint (sofia code) * @@ -3542,65 +3541,13 @@ void launch_sofia_profile_thread(sofia_profile_t *profile) switch_thread_create(&profile->thread, thd_attr, sofia_profile_thread_run, profile, profile->pool); } -static int is_packet_begin_or_end(char *mybuf) -{ - if (!strncasecmp( mybuf, "recv ", 3) || !strncasecmp( mybuf, "send ", 3) ) { - // Buffer starts with "recv" or "send", this means it's a new packet - if (strstr(mybuf, "------------------------------------------------------------------------") != NULL) { - // Buffer also contains the dahsed line, this is good, the complete "header" so to speak - return 1; - } - } else if (!strcmp(mybuf, " ------------------------------------------------------------------------\n")) { - // Buffer only has the dashed line, this means it is the end of a packet - return 2; - } - return 0; -} - static void logger(void *logarg, char const *fmt, va_list ap) { - filter_packet_state_t filter_packet_state; - char buf[1024]; - static switch_stream_handle_t packetstream = { 0 }; - static switch_bool_t print_this_packet = SWITCH_FALSE; - static int ovector[30]; - - va_list temp_ap; - va_copy(temp_ap,ap); - - if (!fmt) return; + if (!fmt) return; - vsnprintf( buf, 1024, fmt, temp_ap); - buf[sizeof(buf)-1] = '\0'; - - if (mod_sofia_globals.filtering) { - if (switch_regex_perform( buf, mod_sofia_globals.filter_expression, &mod_sofia_globals.filter_re, ovector, sizeof(ovector) / sizeof(ovector[0]) ) > 0) { - print_this_packet = SWITCH_TRUE; - } - - filter_packet_state = is_packet_begin_or_end(buf); - - if ( filter_packet_state == FILTER_BEGIN ) { - print_this_packet = SWITCH_FALSE; - SWITCH_STANDARD_STREAM(packetstream); - packetstream.write_function(&packetstream, "%s", buf); - - } else if ( filter_packet_state == FILTER_END ) { - if ( print_this_packet == SWITCH_TRUE ) { - switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, mod_sofia_globals.tracelevel, "\nFILTER REGEX (%s) FOUND IN: \n <<<%s>>>\n", mod_sofia_globals.filter_expression, (char *)packetstream.data ); - } - switch_safe_free(packetstream.data); - - } else { - packetstream.write_function(&packetstream, "%s", buf); - } - } else { - switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, mod_sofia_globals.tracelevel, "%s", buf ); - } - buf[0] = '\0'; + switch_log_vprintf(SWITCH_CHANNEL_LOG_CLEAN, mod_sofia_globals.tracelevel, fmt, ap); } - static su_log_t *sofia_get_logger(const char *name) { if (!strcasecmp(name, "tport")) {