diff --git a/docs/README.md b/docs/README.md index 4880df5c..9867c1f7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -204,7 +204,7 @@ option during build time, use the `-D OPTION` compiler flag: $ cc app0.c mongoose.c # Use defaults! $ cc app1.c mongoose.c -D MG_ENABLE_IPV6=1 # Build with IPv6 enabled $ cc app2.c mongoose.c -D MG_ARCH=MG_ARCH_FREERTOS_LWIP # Set architecture -$ cc app3.c mongoose.c -D MG_ENABLE_FS=0 -D MG_ENABLE_LOG=0 # Multiple options +$ cc app3.c mongoose.c -D MG_ENABLE_STDIO=0 -D MG_ENABLE_LOG=0 # Multiple options ``` The list of supported @@ -237,7 +237,7 @@ Here is a list of build constants and their default values: |MG_ENABLE_SOCKET | 1 | Use BSD socket low-level API | |MG_ENABLE_MBEDTLS | 0 | Enable Mbed TLS library | |MG_ENABLE_OPENSSL | 0 | Enable OpenSSL library | -|MG_ENABLE_FS | 1 | Enable API that use filesystem, like `mg_http_send_file()` | +|MG_ENABLE_STDIO | 1 | Enable API that use filesystem, like `mg_http_send_file()` | |MG_ENABLE_IPV6 | 0 | Enable IPv6 | |MG_ENABLE_LOG | 1 | Enable `LOG()` macro | |MG_ENABLE_MD5 | 0 | Use native MD5 implementation | diff --git a/examples/stm32-freertos-tcp/Makefile b/examples/stm32-freertos-tcp/Makefile index 8486b2a5..93060089 100644 --- a/examples/stm32-freertos-tcp/Makefile +++ b/examples/stm32-freertos-tcp/Makefile @@ -6,7 +6,7 @@ DOCKER ?= docker run -it --rm -v $(PROJECT_ROOT_PATH):$(PROJECT_ROOT_PATH) -w $( FREERTOS_KERNEL_PATH ?= $(PROJECT_ROOT_PATH)/test/freertos-kernel FREERTOS_PLUS_TCP_PATH ?= $(PROJECT_ROOT_PATH)/test/freertos-tcp -MONGOOSE_FLAGS = -DMG_ARCH=MG_ARCH_FREERTOS_TCP -DMG_ENABLE_FS=1 +MONGOOSE_FLAGS = -DMG_ARCH=MG_ARCH_FREERTOS_TCP -DMG_ENABLE_STDIO=1 MCU_FLAGS = -mcpu=cortex-m7 -mthumb -mfloat-abi=softfp -mfpu=vfpv4 #-mcpu=cortex-m7 -mthumb -mfpu=fpv5-sp-d16 -mfloat-abi=hard diff --git a/examples/stm32-freertos-tcp/main.c b/examples/stm32-freertos-tcp/main.c index b17e1cf6..2dc99034 100644 --- a/examples/stm32-freertos-tcp/main.c +++ b/examples/stm32-freertos-tcp/main.c @@ -10,7 +10,7 @@ static const char *s_listening_address = "http://0.0.0.0:80"; // Event handler for the listening connection. static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { if (ev == MG_EV_HTTP_MSG) { -#if MG_ENABLE_FS +#if MG_ENABLE_STDIO struct mg_http_serve_opts opts = {.root_dir = "/"}; mg_http_serve_dir(c, ev_data, &opts); #else @@ -99,32 +99,33 @@ uint32_t HAL_GetTick(void) { #include "stm32f7xx_hal_conf.h" #include "stm32fxx_hal_eth.h" -void HAL_ETH_MspInit( ETH_HandleTypeDef* heth ) { - GPIO_InitTypeDef GPIO_InitStructure; - if (heth->Instance == ETH) { - __HAL_RCC_GPIOA_CLK_ENABLE(); - __HAL_RCC_GPIOC_CLK_ENABLE(); - __HAL_RCC_GPIOG_CLK_ENABLE(); +void HAL_ETH_MspInit(ETH_HandleTypeDef *heth) { + GPIO_InitTypeDef GPIO_InitStructure; + if (heth->Instance == ETH) { + __HAL_RCC_GPIOA_CLK_ENABLE(); + __HAL_RCC_GPIOC_CLK_ENABLE(); + __HAL_RCC_GPIOG_CLK_ENABLE(); - GPIO_InitStructure.Speed = GPIO_SPEED_HIGH; - GPIO_InitStructure.Mode = GPIO_MODE_AF_PP; - GPIO_InitStructure.Pull = GPIO_NOPULL; - GPIO_InitStructure.Alternate = GPIO_AF11_ETH; - GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_7; - HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); + GPIO_InitStructure.Speed = GPIO_SPEED_HIGH; + GPIO_InitStructure.Mode = GPIO_MODE_AF_PP; + GPIO_InitStructure.Pull = GPIO_NOPULL; + GPIO_InitStructure.Alternate = GPIO_AF11_ETH; + GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_7; + HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); - GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5; - HAL_GPIO_Init(GPIOC, &GPIO_InitStructure); + GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5; + HAL_GPIO_Init(GPIOC, &GPIO_InitStructure); - GPIO_InitStructure.Pin = GPIO_PIN_2 | GPIO_PIN_11 | GPIO_PIN_13 | GPIO_PIN_14; - HAL_GPIO_Init(GPIOG, &GPIO_InitStructure); + GPIO_InitStructure.Pin = + GPIO_PIN_2 | GPIO_PIN_11 | GPIO_PIN_13 | GPIO_PIN_14; + HAL_GPIO_Init(GPIOG, &GPIO_InitStructure); - HAL_NVIC_SetPriority(ETH_IRQn, 0x7, 0); - HAL_NVIC_EnableIRQ(ETH_IRQn); - - __HAL_RCC_ETH_CLK_ENABLE(); - HAL_NVIC_SetPriorityGrouping( NVIC_PRIORITYGROUP_4 ); - } + HAL_NVIC_SetPriority(ETH_IRQn, 0x7, 0); + HAL_NVIC_EnableIRQ(ETH_IRQn); + + __HAL_RCC_ETH_CLK_ENABLE(); + HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); + } } int vLoggingPrintf(const char *fmt, ...) { diff --git a/mongoose.c b/mongoose.c index 873090cd..96ac19ef 100644 --- a/mongoose.c +++ b/mongoose.c @@ -775,7 +775,7 @@ void mg_http_reply(struct mg_connection *c, int code, const char *headers, if (buf != mem) free(buf); } -#if MG_ENABLE_FS +#if MG_ENABLE_STDIO static void http_cb(struct mg_connection *, int, void *, void *); static void restore_http_cb(struct mg_connection *c) { if (c->pfn_data != NULL) fclose((FILE *) c->pfn_data); @@ -3910,7 +3910,7 @@ struct mg_str mg_url_pass(const char *url) { -#if MG_ENABLE_FS +#if MG_ENABLE_STDIO int mg_stat(const char *path, mg_stat_t *st) { #ifdef _WIN32 wchar_t tmp[MG_PATH_MAX]; @@ -3982,7 +3982,7 @@ bool mg_file_printf(const char *path, const char *fmt, ...) { if (buf != tmp) free(buf); return result; } -#endif // MG_ENABLE_FS +#endif // MG_ENABLE_STDIO void mg_random(void *buf, size_t len) { bool done = false; @@ -3990,14 +3990,14 @@ void mg_random(void *buf, size_t len) { #if MG_ARCH == MG_ARCH_ESP32 while (len--) *p++ = (unsigned char) (esp_random() & 255); #elif MG_ARCH == MG_ARCH_WIN32 -#elif MG_ARCH_UNIX && MG_ENABLE_FS +#elif MG_ARCH_UNIX && MG_ENABLE_STDIO FILE *fp = fopen("/dev/urandom", "rb"); if (fp != NULL) { if (fread(buf, 1, len, fp) == len) done = true; fclose(fp); } #endif - // Fallback to a pseudo random gen + // Fallback to a pseudo random gen if (!done) { while (len--) *p++ = (unsigned char) (rand() & 255); } @@ -4094,9 +4094,10 @@ char *mg_hex(const void *buf, size_t len, char *to) { } static unsigned char mg_unhex_nimble(unsigned char c) { - return (c >= '0' && c <= '9') ? (unsigned char) (c - '0') - : (c >= 'A' && c <= 'F') ? (unsigned char) (c - '7') - : (unsigned char) (c - 'W'); + return (c >= '0' && c <= '9') + ? (unsigned char) (c - '0') + : (c >= 'A' && c <= 'F') ? (unsigned char) (c - '7') + : (unsigned char) (c - 'W'); } unsigned long mg_unhexn(const char *s, size_t len) { diff --git a/mongoose.h b/mongoose.h index 86072a4c..ba03763e 100644 --- a/mongoose.h +++ b/mongoose.h @@ -141,7 +141,7 @@ struct timeval { }; #endif -#if MG_ENABLE_FS +#if MG_ENABLE_STDIO #include #endif @@ -181,7 +181,7 @@ static inline void *mg_calloc(int cnt, size_t size) { #include #include -#if MG_ENABLE_FS +#if MG_ENABLE_STDIO #include #endif @@ -407,8 +407,8 @@ static __inline struct tm *localtime_r(time_t *t, struct tm *tm) { #define MG_ENABLE_OPENSSL 0 #endif -#ifndef MG_ENABLE_FS -#define MG_ENABLE_FS 1 +#ifndef MG_ENABLE_STDIO +#define MG_ENABLE_STDIO 1 #endif #ifndef MG_ENABLE_SSI @@ -561,7 +561,7 @@ double mg_time(void); unsigned long mg_millis(void); void mg_usleep(unsigned long usecs); -#if MG_ENABLE_FS +#if MG_ENABLE_STDIO #ifdef _WIN32 typedef struct _stati64 mg_stat_t; #else diff --git a/src/arch_freertos_lwip.h b/src/arch_freertos_lwip.h index 0c60d295..53cdc740 100644 --- a/src/arch_freertos_lwip.h +++ b/src/arch_freertos_lwip.h @@ -17,7 +17,7 @@ struct timeval { }; #endif -#if MG_ENABLE_FS +#if MG_ENABLE_STDIO #include #endif diff --git a/src/arch_freertos_tcp.h b/src/arch_freertos_tcp.h index fd76e111..29932732 100644 --- a/src/arch_freertos_tcp.h +++ b/src/arch_freertos_tcp.h @@ -13,7 +13,7 @@ #include #include -#if MG_ENABLE_FS +#if MG_ENABLE_STDIO #include #endif diff --git a/src/config.h b/src/config.h index 86030697..cf40c5fd 100644 --- a/src/config.h +++ b/src/config.h @@ -12,8 +12,8 @@ #define MG_ENABLE_OPENSSL 0 #endif -#ifndef MG_ENABLE_FS -#define MG_ENABLE_FS 1 +#ifndef MG_ENABLE_STDIO +#define MG_ENABLE_STDIO 1 #endif #ifndef MG_ENABLE_SSI diff --git a/src/http.c b/src/http.c index 2f045971..689871fc 100644 --- a/src/http.c +++ b/src/http.c @@ -364,7 +364,7 @@ void mg_http_reply(struct mg_connection *c, int code, const char *headers, if (buf != mem) free(buf); } -#if MG_ENABLE_FS +#if MG_ENABLE_STDIO static void http_cb(struct mg_connection *, int, void *, void *); static void restore_http_cb(struct mg_connection *c) { if (c->pfn_data != NULL) fclose((FILE *) c->pfn_data); diff --git a/src/util.c b/src/util.c index 2fe80de9..54fb4a4e 100644 --- a/src/util.c +++ b/src/util.c @@ -2,7 +2,7 @@ #include "util.h" -#if MG_ENABLE_FS +#if MG_ENABLE_STDIO int mg_stat(const char *path, mg_stat_t *st) { #ifdef _WIN32 wchar_t tmp[MG_PATH_MAX]; @@ -74,7 +74,7 @@ bool mg_file_printf(const char *path, const char *fmt, ...) { if (buf != tmp) free(buf); return result; } -#endif // MG_ENABLE_FS +#endif // MG_ENABLE_STDIO void mg_random(void *buf, size_t len) { bool done = false; @@ -82,14 +82,14 @@ void mg_random(void *buf, size_t len) { #if MG_ARCH == MG_ARCH_ESP32 while (len--) *p++ = (unsigned char) (esp_random() & 255); #elif MG_ARCH == MG_ARCH_WIN32 -#elif MG_ARCH_UNIX && MG_ENABLE_FS +#elif MG_ARCH_UNIX && MG_ENABLE_STDIO FILE *fp = fopen("/dev/urandom", "rb"); if (fp != NULL) { if (fread(buf, 1, len, fp) == len) done = true; fclose(fp); } #endif - // Fallback to a pseudo random gen + // Fallback to a pseudo random gen if (!done) { while (len--) *p++ = (unsigned char) (rand() & 255); } @@ -186,9 +186,10 @@ char *mg_hex(const void *buf, size_t len, char *to) { } static unsigned char mg_unhex_nimble(unsigned char c) { - return (c >= '0' && c <= '9') ? (unsigned char) (c - '0') - : (c >= 'A' && c <= 'F') ? (unsigned char) (c - '7') - : (unsigned char) (c - 'W'); + return (c >= '0' && c <= '9') + ? (unsigned char) (c - '0') + : (c >= 'A' && c <= 'F') ? (unsigned char) (c - '7') + : (unsigned char) (c - 'W'); } unsigned long mg_unhexn(const char *s, size_t len) { diff --git a/src/util.h b/src/util.h index b436310c..f530f74d 100644 --- a/src/util.h +++ b/src/util.h @@ -37,7 +37,7 @@ double mg_time(void); unsigned long mg_millis(void); void mg_usleep(unsigned long usecs); -#if MG_ENABLE_FS +#if MG_ENABLE_STDIO #ifdef _WIN32 typedef struct _stati64 mg_stat_t; #else