mirror of
https://github.com/cesanta/mongoose.git
synced 2025-01-14 01:38:01 +08:00
Remove MG_ENABLE_STDIO and cleanup
This commit is contained in:
parent
d130c6f42d
commit
2a2c17a232
2
Makefile
2
Makefile
@ -118,7 +118,7 @@ mongoose.c: $(SRCS) Makefile
|
||||
(cat src/license.h; echo; echo '#include "mongoose.h"' ; (for F in src/private.h src/*.c ; do echo; echo '#ifdef MG_ENABLE_LINES'; echo "#line 1 \"$$F\""; echo '#endif'; cat $$F | sed -e 's,#include ".*,,'; done))> $@
|
||||
|
||||
mongoose.h: $(HDRS) Makefile
|
||||
(cat src/license.h src/version.h ; cat src/config.h src/arch.h src/arch_*.h src/str.h src/log.h src/timer.h src/util.h src/url.h src/iobuf.h src/base64.h src/md5.h src/sha1.h src/event.h src/net.h src/http.h src/ssi.h src/tls.h src/ws.h src/sntp.h src/mqtt.h src/dns.h | sed -e 's,#include ".*,,' -e 's,^#pragma once,,'; echo; echo '#ifdef __cplusplus'; echo '}'; echo '#endif'; echo '#endif // MONGOOSE_H')> $@
|
||||
(cat src/license.h src/version.h ; cat src/config.h src/arch.h src/arch_*.h src/str.h src/log.h src/timer.h src/util.h src/fs.h src/url.h src/iobuf.h src/base64.h src/md5.h src/sha1.h src/event.h src/net.h src/http.h src/ssi.h src/tls.h src/ws.h src/sntp.h src/mqtt.h src/dns.h | sed -e 's,#include ".*,,' -e 's,^#pragma once,,'; echo; echo '#ifdef __cplusplus'; echo '}'; echo '#endif'; echo '#endif // MONGOOSE_H')> $@
|
||||
|
||||
clean: EXAMPLE_TARGET = clean
|
||||
clean: ex
|
||||
|
@ -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_STDIO=0 -D MG_ENABLE_LOG=0 # Multiple options
|
||||
$ cc app3.c mongoose.c -D MG_ENABLE_SSI=1 -D MG_ENABLE_LOG=0 # Multiple options
|
||||
```
|
||||
|
||||
The list of supported
|
||||
@ -237,7 +237,6 @@ 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_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 |
|
||||
|
@ -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_STDIO=1
|
||||
MONGOOSE_FLAGS = -DMG_ARCH=MG_ARCH_FREERTOS_TCP
|
||||
MCU_FLAGS = -mcpu=cortex-m7 -mthumb -mfloat-abi=softfp -mfpu=vfpv4
|
||||
#-mcpu=cortex-m7 -mthumb -mfpu=fpv5-sp-d16 -mfloat-abi=hard
|
||||
|
||||
|
@ -10,12 +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_STDIO
|
||||
struct mg_http_serve_opts opts = {.root_dir = "/"};
|
||||
mg_http_serve_dir(c, ev_data, &opts);
|
||||
#else
|
||||
mg_http_reply(c, 200, "", "hello, %s!\n", "world");
|
||||
#endif
|
||||
}
|
||||
(void) fn_data;
|
||||
(void) ev_data;
|
||||
|
31
mongoose.c
31
mongoose.c
@ -406,6 +406,21 @@ void mg_error(struct mg_connection *c, const char *fmt, ...) {
|
||||
c->is_closing = 1;
|
||||
}
|
||||
|
||||
#ifdef MG_ENABLE_LINES
|
||||
#line 1 "src/fs.c"
|
||||
#endif
|
||||
|
||||
|
||||
int mg_stat(const char *path, mg_stat_t *st) {
|
||||
#ifdef _WIN32
|
||||
wchar_t tmp[MG_PATH_MAX];
|
||||
MultiByteToWideChar(CP_UTF8, 0, path, -1, tmp, sizeof(tmp) / sizeof(tmp[0]));
|
||||
return _wstati64(tmp, st);
|
||||
#else
|
||||
return stat(path, st);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef MG_ENABLE_LINES
|
||||
#line 1 "src/http.c"
|
||||
#endif
|
||||
@ -775,7 +790,6 @@ void mg_http_reply(struct mg_connection *c, int code, const char *headers,
|
||||
if (buf != mem) free(buf);
|
||||
}
|
||||
|
||||
#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);
|
||||
@ -1298,7 +1312,6 @@ void mg_http_serve_dir(struct mg_connection *c, struct mg_http_message *hm,
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool mg_is_url_safe(int c) {
|
||||
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') ||
|
||||
@ -3910,17 +3923,6 @@ struct mg_str mg_url_pass(const char *url) {
|
||||
|
||||
|
||||
|
||||
#if MG_ENABLE_STDIO
|
||||
int mg_stat(const char *path, mg_stat_t *st) {
|
||||
#ifdef _WIN32
|
||||
wchar_t tmp[MG_PATH_MAX];
|
||||
MultiByteToWideChar(CP_UTF8, 0, path, -1, tmp, sizeof(tmp) / sizeof(tmp[0]));
|
||||
return _wstati64(tmp, st);
|
||||
#else
|
||||
return stat(path, st);
|
||||
#endif
|
||||
}
|
||||
|
||||
char *mg_file_read(const char *path, size_t *sizep) {
|
||||
FILE *fp;
|
||||
char *data = NULL;
|
||||
@ -3975,7 +3977,6 @@ bool mg_file_printf(const char *path, const char *fmt, ...) {
|
||||
if (buf != tmp) free(buf);
|
||||
return result;
|
||||
}
|
||||
#endif // MG_ENABLE_STDIO
|
||||
|
||||
void mg_random(void *buf, size_t len) {
|
||||
bool done = false;
|
||||
@ -3983,7 +3984,7 @@ 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_STDIO
|
||||
#elif MG_ARCH_UNIX
|
||||
FILE *fp = fopen("/dev/urandom", "rb");
|
||||
if (fp != NULL) {
|
||||
if (fread(buf, 1, len, fp) == len) done = true;
|
||||
|
39
mongoose.h
39
mongoose.h
@ -37,14 +37,6 @@ extern "C" {
|
||||
#define MG_ENABLE_OPENSSL 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_PACKED_FS
|
||||
#define MG_ENABLE_PACKED_FS 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_STDIO
|
||||
#define MG_ENABLE_STDIO 1
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_SSI
|
||||
#define MG_ENABLE_SSI 0
|
||||
#endif
|
||||
@ -200,6 +192,7 @@ extern "C" {
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#else
|
||||
typedef long suseconds_t;
|
||||
@ -209,10 +202,6 @@ struct timeval {
|
||||
};
|
||||
#endif
|
||||
|
||||
#if MG_ENABLE_STDIO
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
|
||||
@ -247,11 +236,8 @@ static inline void *mg_calloc(int cnt, size_t size) {
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#if MG_ENABLE_STDIO
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
#include <time.h>
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <FreeRTOS_IP.h>
|
||||
@ -287,6 +273,7 @@ static inline void *mg_calloc(int cnt, size_t size) {
|
||||
FreeRTOS_recvfrom((a), (b), (c), (d), (e), (f))
|
||||
#define closesocket(x) FreeRTOS_closesocket(x)
|
||||
#define gethostbyname(x) FreeRTOS_gethostbyname(x)
|
||||
#define getsockname(a, b, c) (-1)
|
||||
|
||||
// Re-route calloc/free to the FreeRTOS's functions, don't use stdlib
|
||||
static inline void *mg_calloc(int cnt, size_t size) {
|
||||
@ -563,15 +550,6 @@ double mg_time(void);
|
||||
unsigned long mg_millis(void);
|
||||
void mg_usleep(unsigned long usecs);
|
||||
|
||||
#if MG_ENABLE_STDIO
|
||||
#ifdef _WIN32
|
||||
typedef struct _stati64 mg_stat_t;
|
||||
#else
|
||||
typedef struct stat mg_stat_t;
|
||||
#endif
|
||||
int mg_stat(const char *path, mg_stat_t *);
|
||||
#endif
|
||||
|
||||
#define mg_htons(x) mg_ntohs(x)
|
||||
#define mg_htonl(x) mg_ntohl(x)
|
||||
|
||||
@ -610,6 +588,16 @@ int mg_stat(const char *path, mg_stat_t *);
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
typedef struct _stati64 mg_stat_t;
|
||||
#else
|
||||
typedef struct stat mg_stat_t;
|
||||
#endif
|
||||
int mg_stat(const char *path, mg_stat_t *);
|
||||
|
||||
|
||||
|
||||
unsigned short mg_url_port(const char *url);
|
||||
int mg_url_is_ssl(const char *url);
|
||||
struct mg_str mg_url_host(const char *url);
|
||||
@ -793,6 +781,7 @@ struct mg_http_serve_opts {
|
||||
const char *root_dir; // Web root directory, must be non-NULL
|
||||
const char *ssi_pattern; // SSI file name pattern, e.g. #.shtml
|
||||
const char *extra_headers; // Extra HTTP headers to add in responses
|
||||
bool use_packed_fs; // Serve files embedded into binary
|
||||
};
|
||||
|
||||
// Parameter for mg_http_next_multipart
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#else
|
||||
typedef long suseconds_t;
|
||||
@ -17,10 +18,6 @@ struct timeval {
|
||||
};
|
||||
#endif
|
||||
|
||||
#if MG_ENABLE_STDIO
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
|
||||
|
@ -11,11 +11,8 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#if MG_ENABLE_STDIO
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
#include <time.h>
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <FreeRTOS_IP.h>
|
||||
@ -51,6 +48,7 @@
|
||||
FreeRTOS_recvfrom((a), (b), (c), (d), (e), (f))
|
||||
#define closesocket(x) FreeRTOS_closesocket(x)
|
||||
#define gethostbyname(x) FreeRTOS_gethostbyname(x)
|
||||
#define getsockname(a, b, c) (-1)
|
||||
|
||||
// Re-route calloc/free to the FreeRTOS's functions, don't use stdlib
|
||||
static inline void *mg_calloc(int cnt, size_t size) {
|
||||
|
@ -12,14 +12,6 @@
|
||||
#define MG_ENABLE_OPENSSL 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_PACKED_FS
|
||||
#define MG_ENABLE_PACKED_FS 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_STDIO
|
||||
#define MG_ENABLE_STDIO 1
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_SSI
|
||||
#define MG_ENABLE_SSI 0
|
||||
#endif
|
||||
|
11
src/fs.c
Normal file
11
src/fs.c
Normal file
@ -0,0 +1,11 @@
|
||||
#include "fs.h"
|
||||
|
||||
int mg_stat(const char *path, mg_stat_t *st) {
|
||||
#ifdef _WIN32
|
||||
wchar_t tmp[MG_PATH_MAX];
|
||||
MultiByteToWideChar(CP_UTF8, 0, path, -1, tmp, sizeof(tmp) / sizeof(tmp[0]));
|
||||
return _wstati64(tmp, st);
|
||||
#else
|
||||
return stat(path, st);
|
||||
#endif
|
||||
}
|
10
src/fs.h
Normal file
10
src/fs.h
Normal file
@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "arch.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
typedef struct _stati64 mg_stat_t;
|
||||
#else
|
||||
typedef struct stat mg_stat_t;
|
||||
#endif
|
||||
int mg_stat(const char *path, mg_stat_t *);
|
@ -364,7 +364,6 @@ void mg_http_reply(struct mg_connection *c, int code, const char *headers,
|
||||
if (buf != mem) free(buf);
|
||||
}
|
||||
|
||||
#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);
|
||||
@ -887,7 +886,6 @@ void mg_http_serve_dir(struct mg_connection *c, struct mg_http_message *hm,
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool mg_is_url_safe(int c) {
|
||||
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') ||
|
||||
|
@ -23,6 +23,7 @@ struct mg_http_serve_opts {
|
||||
const char *root_dir; // Web root directory, must be non-NULL
|
||||
const char *ssi_pattern; // SSI file name pattern, e.g. #.shtml
|
||||
const char *extra_headers; // Extra HTTP headers to add in responses
|
||||
bool use_packed_fs; // Serve files embedded into binary
|
||||
};
|
||||
|
||||
// Parameter for mg_http_next_multipart
|
||||
|
14
src/util.c
14
src/util.c
@ -2,17 +2,6 @@
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#if MG_ENABLE_STDIO
|
||||
int mg_stat(const char *path, mg_stat_t *st) {
|
||||
#ifdef _WIN32
|
||||
wchar_t tmp[MG_PATH_MAX];
|
||||
MultiByteToWideChar(CP_UTF8, 0, path, -1, tmp, sizeof(tmp) / sizeof(tmp[0]));
|
||||
return _wstati64(tmp, st);
|
||||
#else
|
||||
return stat(path, st);
|
||||
#endif
|
||||
}
|
||||
|
||||
char *mg_file_read(const char *path, size_t *sizep) {
|
||||
FILE *fp;
|
||||
char *data = NULL;
|
||||
@ -67,7 +56,6 @@ bool mg_file_printf(const char *path, const char *fmt, ...) {
|
||||
if (buf != tmp) free(buf);
|
||||
return result;
|
||||
}
|
||||
#endif // MG_ENABLE_STDIO
|
||||
|
||||
void mg_random(void *buf, size_t len) {
|
||||
bool done = false;
|
||||
@ -75,7 +63,7 @@ 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_STDIO
|
||||
#elif MG_ARCH_UNIX
|
||||
FILE *fp = fopen("/dev/urandom", "rb");
|
||||
if (fp != NULL) {
|
||||
if (fread(buf, 1, len, fp) == len) done = true;
|
||||
|
@ -36,15 +36,6 @@ double mg_time(void);
|
||||
unsigned long mg_millis(void);
|
||||
void mg_usleep(unsigned long usecs);
|
||||
|
||||
#if MG_ENABLE_STDIO
|
||||
#ifdef _WIN32
|
||||
typedef struct _stati64 mg_stat_t;
|
||||
#else
|
||||
typedef struct stat mg_stat_t;
|
||||
#endif
|
||||
int mg_stat(const char *path, mg_stat_t *);
|
||||
#endif
|
||||
|
||||
#define mg_htons(x) mg_ntohs(x)
|
||||
#define mg_htonl(x) mg_ntohl(x)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user