Skip to content

Commit

Permalink
dtls_debug: mock dsrv_log() when NDEBUG is set
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
benpicco authored and boaks committed Jul 24, 2023
1 parent 7fd6414 commit ba830a3
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions dtls_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit ba830a3

Please sign in to comment.