From 241090a82b87a3b42b93941b8799d9fd3abc60cf Mon Sep 17 00:00:00 2001
From: Deomid Ryabkov <rojer@cesanta.com>
Date: Fri, 14 Oct 2016 13:15:11 +0300
Subject: [PATCH] CS_DISABLE_(STDIO|HEXDUMP) -> CS_ENABLE_$1

PUBLISHED_FROM=9fd0cebfa8df53b5d9574a8d013305ddda5e7a18
---
 docs/c-api/net.h/struct_mg_mgr.md            |   2 +
 examples/CC3200/cs_dbg.h                     |  14 ++-
 examples/ESP8266_RTOS/build.sh               |  10 ++
 examples/ESP8266_RTOS/sdk.version            |   1 +
 examples/ESP8266_RTOS/user/cs_dbg.h          |   1 -
 examples/ESP8266_RTOS/user/user_main.c       |  23 ++--
 examples/MSP432/ccs/MSP432_MG_hello/cs_dbg.h |  14 ++-
 mongoose.c                                   | 110 +++++++++----------
 mongoose.h                                   |  75 +++++++------
 9 files changed, 140 insertions(+), 110 deletions(-)
 create mode 100755 examples/ESP8266_RTOS/build.sh
 create mode 100644 examples/ESP8266_RTOS/sdk.version
 delete mode 120000 examples/ESP8266_RTOS/user/cs_dbg.h

diff --git a/docs/c-api/net.h/struct_mg_mgr.md b/docs/c-api/net.h/struct_mg_mgr.md
index eac8075fb..cc7790365 100644
--- a/docs/c-api/net.h/struct_mg_mgr.md
+++ b/docs/c-api/net.h/struct_mg_mgr.md
@@ -5,7 +5,9 @@ symbol_kind: "struct"
 signature: |
   struct mg_mgr {
     struct mg_connection *active_connections;
+  #if MG_ENABLE_HEXDUMP
     const char *hexdump_file; /* Debug hexdump file path */
+  #endif
   #if !MG_DISABLE_SOCKETPAIR
     sock_t ctl[2]; /* Socketpair for mg_broadcast() */
   #endif
diff --git a/examples/CC3200/cs_dbg.h b/examples/CC3200/cs_dbg.h
index 813413d59..3befca148 100644
--- a/examples/CC3200/cs_dbg.h
+++ b/examples/CC3200/cs_dbg.h
@@ -6,10 +6,18 @@
 #ifndef CS_COMMON_CS_DBG_H_
 #define CS_COMMON_CS_DBG_H_
 
-#if !CS_DISABLE_STDIO
+#if CS_ENABLE_STDIO
 #include <stdio.h>
 #endif
 
+#ifndef CS_ENABLE_DEBUG
+#define CS_ENABLE_DEBUG 0
+#endif
+
+#ifndef CS_LOG_TS_DIFF
+#define CS_LOG_TS_DIFF 0
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
@@ -28,7 +36,7 @@ enum cs_log_level {
 
 void cs_log_set_level(enum cs_log_level level);
 
-#if !CS_DISABLE_STDIO
+#if CS_ENABLE_STDIO
 
 void cs_log_set_file(FILE *file);
 
@@ -56,7 +64,7 @@ void cs_log_printf(const char *fmt, ...);
 
 #endif
 
-#else /* CS_DISABLE_STDIO */
+#else /* CS_ENABLE_STDIO */
 
 #define LOG(l, x)
 #define DBG(x)
diff --git a/examples/ESP8266_RTOS/build.sh b/examples/ESP8266_RTOS/build.sh
new file mode 100755
index 000000000..9bcd891c7
--- /dev/null
+++ b/examples/ESP8266_RTOS/build.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+docker run \
+  --rm -i -v $(realpath ${PWD}/../..):/src \
+  --entrypoint=/bin/bash $(cat sdk.version) -l -c -x '
+    export SDK_PATH=/opt/Espressif/ESP8266_SDK;
+    export BIN_PATH=./bin;
+    cd /src/examples/ESP8266_RTOS &&
+    mkdir -p ./bin && make clean &&
+    make BOOT=none APP=0 SPI_SPEED=40 SPI_MODE=qio SPI_SIZE_MAP=0'
diff --git a/examples/ESP8266_RTOS/sdk.version b/examples/ESP8266_RTOS/sdk.version
new file mode 100644
index 000000000..960f7975d
--- /dev/null
+++ b/examples/ESP8266_RTOS/sdk.version
@@ -0,0 +1 @@
+docker.cesanta.com/esp8266-build-rtos:1.4.0-r2
diff --git a/examples/ESP8266_RTOS/user/cs_dbg.h b/examples/ESP8266_RTOS/user/cs_dbg.h
deleted file mode 120000
index a2154b8aa..000000000
--- a/examples/ESP8266_RTOS/user/cs_dbg.h
+++ /dev/null
@@ -1 +0,0 @@
-./../../../../common/cs_dbg.h
\ No newline at end of file
diff --git a/examples/ESP8266_RTOS/user/user_main.c b/examples/ESP8266_RTOS/user/user_main.c
index 892c2a52a..f54858c28 100644
--- a/examples/ESP8266_RTOS/user/user_main.c
+++ b/examples/ESP8266_RTOS/user/user_main.c
@@ -6,7 +6,6 @@
 #include "esp_common.h"
 
 #include "mongoose.h"
-#include "cs_dbg.h"
 
 #define AP_SSID "Mongoose"
 #define AP_PASS "Mongoose"
@@ -25,14 +24,13 @@ void ev_handler(struct mg_connection *nc, int ev, void *p) {
       "Content-Type: text/plain\r\n"
       "\r\n"
       "Hello %s\n";
-  LOG(LL_DEBUG, ("conn %p ev %d", nc, ev));
 
   switch (ev) {
     case MG_EV_ACCEPT: {
       char addr[32];
       mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr),
                           MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT);
-      LOG(LL_INFO, ("Connection %p from %s", nc, addr));
+      printf("Connection %p from %s\n", nc, addr);
       break;
     }
     case MG_EV_HTTP_REQUEST: {
@@ -40,15 +38,14 @@ void ev_handler(struct mg_connection *nc, int ev, void *p) {
       struct http_message *hm = (struct http_message *) p;
       mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr),
                           MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT);
-      LOG(LL_INFO,
-          ("HTTP request from %s: %.*s %.*s", addr, (int) hm->method.len,
-           hm->method.p, (int) hm->uri.len, hm->uri.p));
+      printf("HTTP request from %s: %.*s %.*s\n", addr, (int) hm->method.len,
+             hm->method.p, (int) hm->uri.len, hm->uri.p);
       mg_printf(nc, reply_fmt, addr);
       nc->flags |= MG_F_SEND_AND_CLOSE;
       break;
     }
     case MG_EV_CLOSE: {
-      LOG(LL_INFO, ("Connection %p closed", nc));
+      printf("Connection %p closed\n", nc);
       break;
     }
   }
@@ -71,30 +68,28 @@ void setup_ap(void) {
   cfg.max_connection = 10;
   cfg.beacon_interval = 100; /* ms */
 
-  LOG(LL_INFO, ("Setting up AP '%s' on channel %d", cfg.ssid, cfg.channel));
+  printf("Setting up AP '%s' on channel %d\n", cfg.ssid, cfg.channel);
   wifi_softap_set_config_current(&cfg);
   wifi_softap_dhcps_stop();
   wifi_softap_set_dhcps_offer_option(OFFER_ROUTER, &off);
   wifi_softap_dhcps_start();
   wifi_get_ip_info(SOFTAP_IF, &info);
-  LOG(LL_INFO, ("WiFi AP: SSID %s, channel %d, IP " IPSTR "", cfg.ssid,
-                cfg.channel, IP2STR(&info.ip)));
+  printf("WiFi AP: SSID %s, channel %d, IP " IPSTR "\n", cfg.ssid, cfg.channel,
+         IP2STR(&info.ip));
 }
 
 static void mg_task(void *arg) {
   struct mg_mgr mgr;
   struct mg_connection *nc;
 
-  cs_log_set_level(LL_INFO);
-
-  LOG(LL_INFO, ("SDK version: %s", system_get_sdk_version()));
+  printf("SDK version: %s\n", system_get_sdk_version());
   setup_ap();
 
   mg_mgr_init(&mgr, NULL);
 
   nc = mg_bind(&mgr, MG_LISTEN_ADDR, ev_handler);
   if (nc == NULL) {
-    LOG(LL_ERROR, ("Error setting up listener!"));
+    printf("Error setting up listener!\n");
     return;
   }
   mg_set_protocol_http_websocket(nc);
diff --git a/examples/MSP432/ccs/MSP432_MG_hello/cs_dbg.h b/examples/MSP432/ccs/MSP432_MG_hello/cs_dbg.h
index 813413d59..3befca148 100644
--- a/examples/MSP432/ccs/MSP432_MG_hello/cs_dbg.h
+++ b/examples/MSP432/ccs/MSP432_MG_hello/cs_dbg.h
@@ -6,10 +6,18 @@
 #ifndef CS_COMMON_CS_DBG_H_
 #define CS_COMMON_CS_DBG_H_
 
-#if !CS_DISABLE_STDIO
+#if CS_ENABLE_STDIO
 #include <stdio.h>
 #endif
 
+#ifndef CS_ENABLE_DEBUG
+#define CS_ENABLE_DEBUG 0
+#endif
+
+#ifndef CS_LOG_TS_DIFF
+#define CS_LOG_TS_DIFF 0
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
@@ -28,7 +36,7 @@ enum cs_log_level {
 
 void cs_log_set_level(enum cs_log_level level);
 
-#if !CS_DISABLE_STDIO
+#if CS_ENABLE_STDIO
 
 void cs_log_set_file(FILE *file);
 
@@ -56,7 +64,7 @@ void cs_log_printf(const char *fmt, ...);
 
 #endif
 
-#else /* CS_DISABLE_STDIO */
+#else /* CS_ENABLE_STDIO */
 
 #define LOG(l, x)
 #define DBG(x)
diff --git a/mongoose.c b/mongoose.c
index 3b2e3f816..08ed1d2d1 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -160,8 +160,10 @@ MG_INTERNAL void mg_handle_put(struct mg_connection *nc, const char *path,
 #ifndef CS_COMMON_CS_DBG_H_
 #define CS_COMMON_CS_DBG_H_
 
-#ifndef CS_DISABLE_STDIO
-#define CS_DISABLE_STDIO 0
+/* Amalgamated: #include "common/platform.h" */
+
+#if CS_ENABLE_STDIO
+#include <stdio.h>
 #endif
 
 #ifndef CS_ENABLE_DEBUG
@@ -172,10 +174,6 @@ MG_INTERNAL void mg_handle_put(struct mg_connection *nc, const char *path,
 #define CS_LOG_TS_DIFF 0
 #endif
 
-#if !CS_DISABLE_STDIO
-#include <stdio.h>
-#endif
-
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
@@ -194,7 +192,7 @@ enum cs_log_level {
 
 void cs_log_set_level(enum cs_log_level level);
 
-#if !CS_DISABLE_STDIO
+#if CS_ENABLE_STDIO
 
 void cs_log_set_file(FILE *file);
 
@@ -222,7 +220,7 @@ void cs_log_printf(const char *fmt, ...);
 
 #endif
 
-#else /* CS_DISABLE_STDIO */
+#else /* CS_ENABLE_STDIO */
 
 #define LOG(l, x)
 #define DBG(x)
@@ -256,7 +254,7 @@ enum cs_log_level cs_log_level =
     LL_ERROR;
 #endif
 
-#if !CS_DISABLE_STDIO
+#if CS_ENABLE_STDIO
 
 FILE *cs_log_file = NULL;
 
@@ -289,11 +287,11 @@ void cs_log_set_file(FILE *file) {
   cs_log_file = file;
 }
 
-#endif /* !CS_DISABLE_STDIO */
+#endif /* CS_ENABLE_STDIO */
 
 void cs_log_set_level(enum cs_log_level level) {
   cs_log_level = level;
-#if CS_LOG_TS_DIFF && !CS_DISABLE_STDIO
+#if CS_LOG_TS_DIFF && CS_ENABLE_STDIO
   cs_log_ts = cs_time();
 #endif
 }
@@ -426,7 +424,7 @@ void cs_base64_encode(const unsigned char *src, int src_len, char *dst) {
 #undef BASE64_OUT
 #undef BASE64_FLUSH
 
-#if !CS_DISABLE_STDIO
+#if CS_ENABLE_STDIO
 #define BASE64_OUT(ch)      \
   do {                      \
     fprintf(f, "%c", (ch)); \
@@ -441,7 +439,7 @@ void cs_fprint_base64(FILE *f, const unsigned char *src, int src_len) {
 
 #undef BASE64_OUT
 #undef BASE64_FLUSH
-#endif /* !CS_DISABLE_STDIO */
+#endif /* CS_ENABLE_STDIO */
 
 /* Convert one byte of encoded base64 input stream to 6-bit chunk */
 static unsigned char from_b64(unsigned char ch) {
@@ -1779,7 +1777,7 @@ MG_INTERNAL void mg_call(struct mg_connection *nc,
        ev_handler == nc->handler ? "user" : "proto", ev, ev_data, nc->flags,
        (int) nc->recv_mbuf.len, (int) nc->send_mbuf.len));
 
-#if !defined(NO_LIBC) && !MG_DISABLE_HEXDUMP
+#if !defined(NO_LIBC) && MG_ENABLE_HEXDUMP
   /* LCOV_EXCL_START */
   if (nc->mgr->hexdump_file != NULL && ev != MG_EV_POLL &&
       ev != MG_EV_SEND /* handled separately */) {
@@ -2343,7 +2341,7 @@ void mg_send(struct mg_connection *nc, const void *buf, int len) {
   } else {
     mg_if_tcp_send(nc, buf, len);
   }
-#if !defined(NO_LIBC) && !MG_DISABLE_HEXDUMP
+#if !defined(NO_LIBC) && MG_ENABLE_HEXDUMP
   if (nc->mgr && nc->mgr->hexdump_file != NULL) {
     mg_hexdump_connection(nc, nc->mgr->hexdump_file, buf, len, MG_EV_SEND);
   }
@@ -7799,7 +7797,7 @@ void mg_conn_addr_to_str(struct mg_connection *nc, char *buf, size_t len,
   mg_sock_addr_to_str(&sa, buf, len, flags);
 }
 
-#if !MG_DISABLE_HEXDUMP
+#if MG_ENABLE_HEXDUMP
 int mg_hexdump(const void *buf, int len, char *dst, int dst_len) {
   const unsigned char *p = (const unsigned char *) buf;
   char ascii[17] = "";
@@ -7821,6 +7819,44 @@ int mg_hexdump(const void *buf, int len, char *dst, int dst_len) {
 
   return n;
 }
+
+void mg_hexdump_connection(struct mg_connection *nc, const char *path,
+                           const void *buf, int num_bytes, int ev) {
+  FILE *fp = NULL;
+  char *hexbuf, src[60], dst[60];
+  int buf_size = num_bytes * 5 + 100;
+
+  if (strcmp(path, "-") == 0) {
+    fp = stdout;
+  } else if (strcmp(path, "--") == 0) {
+    fp = stderr;
+#if !MG_DISABLE_FILESYSTEM
+  } else {
+    fp = fopen(path, "a");
+#endif
+  }
+  if (fp == NULL) return;
+
+  mg_conn_addr_to_str(nc, src, sizeof(src),
+                      MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT);
+  mg_conn_addr_to_str(nc, dst, sizeof(dst), MG_SOCK_STRINGIFY_IP |
+                                                MG_SOCK_STRINGIFY_PORT |
+                                                MG_SOCK_STRINGIFY_REMOTE);
+  fprintf(
+      fp, "%lu %p %s %s %s %d\n", (unsigned long) time(NULL), (void *) nc, src,
+      ev == MG_EV_RECV ? "<-" : ev == MG_EV_SEND
+                                    ? "->"
+                                    : ev == MG_EV_ACCEPT
+                                          ? "<A"
+                                          : ev == MG_EV_CONNECT ? "C>" : "XX",
+      dst, num_bytes);
+  if (num_bytes > 0 && (hexbuf = (char *) MG_MALLOC(buf_size)) != NULL) {
+    mg_hexdump(buf, num_bytes, hexbuf, buf_size);
+    fprintf(fp, "%s", hexbuf);
+    MG_FREE(hexbuf);
+  }
+  if (fp != stdin && fp != stdout) fclose(fp);
+}
 #endif
 
 int mg_avprintf(char **buf, size_t size, const char *fmt, va_list ap) {
@@ -7868,48 +7904,6 @@ int mg_asprintf(char **buf, size_t size, const char *fmt, ...) {
   return ret;
 }
 
-#if !MG_DISABLE_HEXDUMP
-void mg_hexdump_connection(struct mg_connection *nc, const char *path,
-                           const void *buf, int num_bytes, int ev) {
-#if !defined(NO_LIBC) && !MG_DISABLE_STDIO
-  FILE *fp = NULL;
-  char *hexbuf, src[60], dst[60];
-  int buf_size = num_bytes * 5 + 100;
-
-  if (strcmp(path, "-") == 0) {
-    fp = stdout;
-  } else if (strcmp(path, "--") == 0) {
-    fp = stderr;
-#if !MG_DISABLE_FILESYSTEM
-  } else {
-    fp = fopen(path, "a");
-#endif
-  }
-  if (fp == NULL) return;
-
-  mg_conn_addr_to_str(nc, src, sizeof(src),
-                      MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT);
-  mg_conn_addr_to_str(nc, dst, sizeof(dst), MG_SOCK_STRINGIFY_IP |
-                                                MG_SOCK_STRINGIFY_PORT |
-                                                MG_SOCK_STRINGIFY_REMOTE);
-  fprintf(
-      fp, "%lu %p %s %s %s %d\n", (unsigned long) time(NULL), (void *) nc, src,
-      ev == MG_EV_RECV ? "<-" : ev == MG_EV_SEND
-                                    ? "->"
-                                    : ev == MG_EV_ACCEPT
-                                          ? "<A"
-                                          : ev == MG_EV_CONNECT ? "C>" : "XX",
-      dst, num_bytes);
-  if (num_bytes > 0 && (hexbuf = (char *) MG_MALLOC(buf_size)) != NULL) {
-    mg_hexdump(buf, num_bytes, hexbuf, buf_size);
-    fprintf(fp, "%s", hexbuf);
-    MG_FREE(hexbuf);
-  }
-  if (fp != stdin && fp != stdout) fclose(fp);
-#endif
-}
-#endif
-
 int mg_is_big_endian(void) {
   static const int n = 1;
   /* TODO(mkm) use compiletime check with 4-byte char literal */
diff --git a/mongoose.h b/mongoose.h
index 0e5bed5ec..4b9206124 100644
--- a/mongoose.h
+++ b/mongoose.h
@@ -30,27 +30,6 @@
 #include <mg_locals.h>
 #endif
 
-#ifndef MG_ENABLE_DEBUG
-#define MG_ENABLE_DEBUG 0
-#endif
-
-#if MG_ENABLE_DEBUG && !defined(CS_ENABLE_DEBUG)
-#define CS_ENABLE_DEBUG 1
-#endif
-
-#ifndef MG_DISABLE_STDIO
-#define MG_DISABLE_STDIO 0
-#endif
-
-#if MG_DISABLE_STDIO && !defined(CS_DISABLE_STDIO)
-#define CS_DISABLE_STDIO 1
-#elif defined(CS_DISABLE_STDIO) && !MG_DISABLE_STDIO
-#undef MG_DISABLE_STDIO
-#define MG_DISABLE_STDIO 1
-#endif
-
-/* Amalgamated: #include "common/cs_dbg.h" */
-
 #endif /* CS_MONGOOSE_SRC_COMMON_H_ */
 #ifdef MG_MODULE_LINES
 #line 1 "common/platform.h"
@@ -262,6 +241,10 @@ typedef struct _stati64 cs_stat_t;
 #define MG_MAX_HTTP_HEADERS 40
 #endif
 
+#ifndef CS_ENABLE_STDIO
+#define CS_ENABLE_STDIO 1
+#endif
+
 #endif /* CS_PLATFORM == CS_P_WINDOWS */
 #endif /* CS_COMMON_PLATFORMS_PLATFORM_WINDOWS_H_ */
 #ifdef MG_MODULE_LINES
@@ -364,6 +347,10 @@ typedef struct stat cs_stat_t;
 #define MG_MAX_HTTP_HEADERS 40
 #endif
 
+#ifndef CS_ENABLE_STDIO
+#define CS_ENABLE_STDIO 1
+#endif
+
 #endif /* CS_PLATFORM == CS_P_UNIX */
 #endif /* CS_COMMON_PLATFORMS_PLATFORM_UNIX_H_ */
 #ifdef MG_MODULE_LINES
@@ -428,6 +415,10 @@ void mg_lwip_set_keepalive_params(struct mg_connection *nc, int idle,
                                   int interval, int count);
 #endif
 
+#ifndef CS_ENABLE_STDIO
+#define CS_ENABLE_STDIO 1
+#endif
+
 #endif /* CS_PLATFORM == CS_P_ESP_LWIP */
 #endif /* CS_COMMON_PLATFORMS_PLATFORM_ESP_LWIP_H_ */
 #ifdef MG_MODULE_LINES
@@ -607,6 +598,10 @@ struct dirent *readdir(DIR *dir);
 #define MG_FS_SLFS
 #endif
 
+#ifndef CS_ENABLE_STDIO
+#define CS_ENABLE_STDIO 1
+#endif
+
 #ifdef __cplusplus
 }
 #endif
@@ -710,6 +705,10 @@ int _stat(const char *pathname, struct stat *st);
 
 #endif /* __TI_COMPILER_VERSION__ */
 
+#ifndef CS_ENABLE_STDIO
+#define CS_ENABLE_STDIO 1
+#endif
+
 #ifdef __cplusplus
 }
 #endif
@@ -730,6 +729,10 @@ int _stat(const char *pathname, struct stat *st);
 
 /* Amalgamated: #include "mbed.h" */
 
+#ifndef CS_ENABLE_STDIO
+#define CS_ENABLE_STDIO 1
+#endif
+
 #endif /* CS_PLATFORM == CS_P_MBED */
 #endif /* CS_COMMON_PLATFORMS_PLATFORM_MBED_H_ */
 #ifdef MG_MODULE_LINES
@@ -1195,10 +1198,6 @@ const char *c_strnstr(const char *s, const char *find, size_t slen);
 #define MG_DISABLE_FILESYSTEM 0
 #endif
 
-#ifndef MG_DISABLE_HEXDUMP
-#define MG_DISABLE_HEXDUMP 0
-#endif
-
 #ifndef MG_DISABLE_HTTP_DIGEST_AUTH
 #define MG_DISABLE_HTTP_DIGEST_AUTH 0
 #endif
@@ -1255,6 +1254,10 @@ const char *c_strnstr(const char *s, const char *find, size_t slen);
 #define MG_ENABLE_COAP 0
 #endif
 
+#ifndef MG_ENABLE_DEBUG
+#define MG_ENABLE_DEBUG 0
+#endif
+
 #ifndef MG_ENABLE_DNS_SERVER
 #define MG_ENABLE_DNS_SERVER 0
 #endif
@@ -1267,6 +1270,10 @@ const char *c_strnstr(const char *s, const char *find, size_t slen);
 #define MG_ENABLE_GETADDRINFO 0
 #endif
 
+#ifndef MG_ENABLE_HEXDUMP
+#define MG_ENABLE_HEXDUMP CS_ENABLE_STDIO
+#endif
+
 #ifndef MG_ENABLE_HTTP_STREAMING_MULTIPART
 #define MG_ENABLE_HTTP_STREAMING_MULTIPART 0
 #endif
@@ -1295,6 +1302,10 @@ const char *c_strnstr(const char *s, const char *find, size_t slen);
 #define MG_ENABLE_SSL 0
 #endif
 
+#ifndef MG_ENABLE_STDIO
+#define MG_ENABLE_STDIO CS_ENABLE_STDIO
+#endif
+
 #ifndef MG_ENABLE_THREADS /* ifdef-ok */
 #ifdef _WIN32
 #define MG_ENABLE_THREADS 1
@@ -1303,16 +1314,14 @@ const char *c_strnstr(const char *s, const char *find, size_t slen);
 #endif
 #endif
 
+#if MG_ENABLE_DEBUG && !defined(CS_ENABLE_DEBUG)
+#define CS_ENABLE_DEBUG 1
+#endif
+
 /* All of the below features depend on filesystem access, disable them. */
 #if MG_DISABLE_FILESYSTEM
-#undef MG_DISABLE_DAV
-#define MG_DISABLE_DAV 1
-#undef MG_DISABLE_CGI
-#define MG_DISABLE_CGI 1
 #undef MG_DISABLE_DIRECTORY_LISTING
 #define MG_DISABLE_DIRECTORY_LISTING 1
-#undef MG_DISABLE_DAV
-#define MG_DISABLE_DAV 1
 #endif /* MG_DISABLE_FILESYSTEM */
 
 #ifdef MG_NO_BSD_SOCKETS
@@ -1427,7 +1436,9 @@ typedef void (*mg_event_handler_t)(struct mg_connection *, int ev, void *);
  */
 struct mg_mgr {
   struct mg_connection *active_connections;
+#if MG_ENABLE_HEXDUMP
   const char *hexdump_file; /* Debug hexdump file path */
+#endif
 #if !MG_DISABLE_SOCKETPAIR
   sock_t ctl[2]; /* Socketpair for mg_broadcast() */
 #endif
@@ -2168,6 +2179,7 @@ void mg_sock_to_str(sock_t sock, char *buf, size_t len, int flags);
 void mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len,
                          int flags);
 
+#if MG_ENABLE_HEXDUMP
 /*
  * Generates a human-readable hexdump of memory chunk.
  *
@@ -2187,6 +2199,7 @@ int mg_hexdump(const void *buf, int len, char *dst, int dst_len);
  */
 void mg_hexdump_connection(struct mg_connection *nc, const char *path,
                            const void *buf, int num_bytes, int ev);
+#endif
 
 /*
  * Prints message to the buffer. If the buffer is large enough to hold the
-- 
GitLab