Skip to content

Commit

Permalink
Unify ndpi debug logging to always use a u16 protocol id
Browse files Browse the repository at this point in the history
 * fixes SonarCloud complaint

Signed-off-by: Toni Uhlig <[email protected]>
  • Loading branch information
utoni committed Nov 7, 2024
1 parent 3b1286a commit 183758e
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 44 deletions.
40 changes: 0 additions & 40 deletions example/ndpiReader.c
Original file line number Diff line number Diff line change
Expand Up @@ -2805,46 +2805,6 @@ static void node_idle_scan_walker(const void *node, ndpi_VISIT which, int depth,

/* *********************************************** */

#if 0
/**
* @brief Print debug
*/
static void debug_printf(u_int32_t protocol, void *id_struct,
ndpi_log_level_t log_level,
const char *format, ...) {
va_list va_ap;
struct tm result;

if(log_level <= nDPI_LogLevel) {
char buf[8192], out_buf[8192];
char theDate[32];
const char *extra_msg = "";
time_t theTime = time(NULL);

va_start (va_ap, format);

if(log_level == NDPI_LOG_ERROR)
extra_msg = "ERROR: ";
else if(log_level == NDPI_LOG_TRACE)
extra_msg = "TRACE: ";
else
extra_msg = "DEBUG: ";

memset(buf, 0, sizeof(buf));
strftime(theDate, 32, "%d/%b/%Y %H:%M:%S", localtime_r(&theTime,&result));
ndpi_snprintf(buf, sizeof(buf)-1, format, va_ap);

ndpi_snprintf(out_buf, sizeof(out_buf), "%s %s%s", theDate, extra_msg, buf);
printf("%s", out_buf);
fflush(stdout);
}

va_end(va_ap);
}
#endif

/* *********************************************** */

static int is_realtime_protocol(ndpi_protocol proto)
{
static u_int16_t const realtime_protos[] = {
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_ds_domain_classify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static struct ndpi_detection_module_struct *ndpi_struct = NULL;
extern "C" {

#ifdef NDPI_ENABLE_DEBUG_MESSAGES
void ndpi_debug_printf(unsigned int proto, struct ndpi_detection_module_struct *ndpi_str, ndpi_log_level_t log_level,
void ndpi_debug_printf(uint16_t proto, struct ndpi_detection_module_struct *ndpi_str, ndpi_log_level_t log_level,
const char *file_name, const char *func_name, unsigned int line_number, const char *format, ...);
#endif

Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_filecfg_malicious_sha1.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "fuzz_common_code.h"

#ifdef NDPI_ENABLE_DEBUG_MESSAGES
void ndpi_debug_printf(unsigned int proto, struct ndpi_detection_module_struct *ndpi_str, ndpi_log_level_t log_level,
void ndpi_debug_printf(uint16_t proto, struct ndpi_detection_module_struct *ndpi_str, ndpi_log_level_t log_level,
const char *file_name, const char *func_name, unsigned int line_number, const char *format, ...);
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/include/ndpi_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ typedef struct ndpi_protocol_bitmask_struct {
struct ndpi_detection_module_struct;

/* NDPI_DEBUG_FUNCTION_PTR (cast) */
typedef void (*ndpi_debug_function_ptr) (u_int32_t protocol, struct ndpi_detection_module_struct *module_struct,
typedef void (*ndpi_debug_function_ptr) (u_int16_t protocol, struct ndpi_detection_module_struct *module_struct,
ndpi_log_level_t log_level, const char *file,
const char *func, unsigned line,
const char *format, ...);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ndpi_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3154,7 +3154,7 @@ void set_ndpi_flow_free(void (*__ndpi_flow_free)(void *ptr)) {
}

#ifdef NDPI_ENABLE_DEBUG_MESSAGES
void ndpi_debug_printf(unsigned int proto, struct ndpi_detection_module_struct *ndpi_str, ndpi_log_level_t log_level,
void ndpi_debug_printf(u_int16_t proto, struct ndpi_detection_module_struct *ndpi_str, ndpi_log_level_t log_level,
const char *file_name, const char *func_name, unsigned int line_number, const char *format, ...) {
va_list args;
#define MAX_STR_LEN 250
Expand Down

0 comments on commit 183758e

Please sign in to comment.