From ba830a390642d057fcf21bbb6bd57546d12e584c Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 27 Feb 2023 16:37:14 +0100 Subject: [PATCH] dtls_debug: mock dsrv_log() when NDEBUG is set Setting NDEBUG already replaces dtls_dsrv_hexdump_log(), dtls_dsrv_log_addr() etc with dummy implementations. This extends this to also replace dsrv_log() and dtls_{get,set}_log_level() with a no-op implementation. --- dtls_debug.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/dtls_debug.c b/dtls_debug.c index ad014669..4b736b8a 100644 --- a/dtls_debug.c +++ b/dtls_debug.c @@ -53,8 +53,6 @@ typedef int in_port_t; LOG_MODULE_REGISTER(TINYDTLS, CONFIG_TINYDTLS_LOG_LEVEL); #endif /* WITH_ZEPHYR */ -static int maxlog = DTLS_LOG_WARN; /* default maximum log level */ - const char *dtls_package_name(void) { return PACKAGE_NAME; } @@ -63,6 +61,9 @@ const char *dtls_package_version(void) { return PACKAGE_VERSION; } +#ifndef NDEBUG +static int maxlog = DTLS_LOG_WARN; /* default maximum log level */ + log_t dtls_get_log_level(void) { return maxlog; @@ -103,8 +104,6 @@ print_timestamp(char *s, size_t len, clock_time_t t) { #endif /* HAVE_TIME_H */ -#ifndef NDEBUG - /** * A length-safe strlen() fake. * @@ -242,8 +241,6 @@ dsrv_print_addr(const session_t *addr, char *buf, size_t len) { #endif /* ! HAVE_INET_NTOP */ } -#endif /* NDEBUG */ - #if !defined(WITH_CONTIKI) && !defined(_MSC_VER) static void @@ -334,7 +331,6 @@ dsrv_log(log_t level, char *format, ...) { } #endif /* WITH_CONTIKI */ -#ifndef NDEBUG /** dumps packets in usual hexdump format */ void hexdump(const unsigned char *packet, int length) { int n = 0; @@ -499,6 +495,16 @@ dtls_dsrv_hexdump_log(log_t level, const char *name, const unsigned char *buf, s #else /* NDEBUG */ +log_t +dtls_get_log_level(void) { + return 0; +} + +void +dtls_set_log_level(log_t level) { + (void)level; +} + void hexdump(const unsigned char *packet, int length) { (void)packet; @@ -520,6 +526,12 @@ dtls_dsrv_hexdump_log(log_t level, const char *name, const unsigned char *buf, s (void)extend; } +void +dsrv_log(log_t level, const char *format, ...) { + (void)level; + (void)format; +} + void dtls_dsrv_log_addr(log_t level, const char *name, const session_t *addr) { (void)level;