mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-16 10:39:49 +00:00
Make mongoose more bare-metal Keil friendly. Declare settings after arch. Introduce MG_ENABLE_FILE
This commit is contained in:
1 parent
9e0f04dc8b
commit
30bfb245f5
13 files changed
+141
-123
No files matched your search
@@ -125,7 +125,7 @@ mongoose.c: Makefile $(wildcard src/*)
|
||||
(cat src/license.h; echo; echo '#include "mongoose.h"' ; (for F in 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; echo; echo '#ifndef MONGOOSE_H'; echo '#define MONGOOSE_H'; echo; cat src/version.h ; echo; echo '#ifdef __cplusplus'; echo 'extern "C" {'; echo '#endif'; 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/tls_mbed.h src/tls_openssl.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; echo; echo '#ifndef MONGOOSE_H'; echo '#define MONGOOSE_H'; echo; cat src/version.h ; echo; echo '#ifdef __cplusplus'; echo 'extern "C" {'; echo '#endif'; cat src/arch.h src/arch_*.h src/config.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/tls_mbed.h src/tls_openssl.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:
|
||||
rm -rf $(PROG) *.o *.dSYM unit_test* ut fuzzer *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb slow-unit* _CL_* infer-out data.txt crash-* test/packed_fs.c pack
|
||||
|
||||
+12
-6
@@ -515,7 +515,7 @@ struct mg_fs mg_fs_packed = {packed_stat, packed_list, packed_open,
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(FOPEN_MAX)
|
||||
#if MG_ENABLE_FILE
|
||||
static int p_stat(const char *path, size_t *size, time_t *mtime) {
|
||||
#ifdef _WIN32
|
||||
struct _stati64 st;
|
||||
@@ -691,9 +691,9 @@ static size_t p_write(void *fp, const void *buf, size_t len) {
|
||||
}
|
||||
|
||||
static size_t p_seek(void *fp, size_t offset) {
|
||||
#if (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) || \
|
||||
(defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || \
|
||||
(defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600)
|
||||
#if (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) || \
|
||||
(defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || \
|
||||
(defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600)
|
||||
fseeko((FILE *) fp, (off_t) offset, SEEK_SET);
|
||||
#else
|
||||
fseek((FILE *) fp, (long) offset, SEEK_SET);
|
||||
@@ -1127,6 +1127,7 @@ char *mg_http_etag(char *buf, size_t len, size_t size, time_t mtime) {
|
||||
return buf;
|
||||
}
|
||||
|
||||
#if MG_ENABLE_FILE
|
||||
int mg_http_upload(struct mg_connection *c, struct mg_http_message *hm,
|
||||
const char *dir) {
|
||||
char offset[40] = "", name[200] = "", path[256];
|
||||
@@ -1152,6 +1153,7 @@ int mg_http_upload(struct mg_connection *c, struct mg_http_message *hm,
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void static_cb(struct mg_connection *c, int ev, void *ev_data,
|
||||
void *fn_data) {
|
||||
@@ -1796,7 +1798,9 @@ void mg_iobuf_free(struct mg_iobuf *io) {
|
||||
#if MG_ENABLE_LOG
|
||||
static void mg_log_stdout(const void *buf, size_t len, void *userdata) {
|
||||
(void) userdata;
|
||||
#if MG_ENABLE_FILE
|
||||
fwrite(buf, 1, len, stdout);
|
||||
#endif
|
||||
}
|
||||
|
||||
static const char *s_spec = "2";
|
||||
@@ -4163,6 +4167,7 @@ struct mg_str mg_url_pass(const char *url) {
|
||||
#include <mach/mach_time.h>
|
||||
#endif
|
||||
|
||||
#if MG_ENABLE_FILE
|
||||
char *mg_file_read(const char *path, size_t *sizep) {
|
||||
FILE *fp;
|
||||
char *data = NULL;
|
||||
@@ -4204,6 +4209,7 @@ bool mg_file_write(const char *path, const void *buf, size_t len) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool mg_file_printf(const char *path, const char *fmt, ...) {
|
||||
char tmp[256], *buf = tmp;
|
||||
@@ -4512,8 +4518,8 @@ unsigned long mg_millis(void) {
|
||||
uint64_t ticks = mach_absolute_time();
|
||||
static mach_timebase_info_data_t timebase;
|
||||
mach_timebase_info(&timebase);
|
||||
double ticks_to_nanos = (double)timebase.numer / timebase.denom;
|
||||
uint64_t uptime_nanos = (uint64_t)(ticks_to_nanos * ticks);
|
||||
double ticks_to_nanos = (double) timebase.numer / timebase.denom;
|
||||
uint64_t uptime_nanos = (uint64_t) (ticks_to_nanos * ticks);
|
||||
return (unsigned long) (uptime_nanos / 1000000);
|
||||
#else
|
||||
struct timespec ts;
|
||||
|
||||
+96
-91
@@ -25,82 +25,6 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef MG_ENABLE_SOCKET
|
||||
#define MG_ENABLE_SOCKET 1
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_MBEDTLS
|
||||
#define MG_ENABLE_MBEDTLS 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_OPENSSL
|
||||
#define MG_ENABLE_OPENSSL 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_CUSTOM_TLS
|
||||
#define MG_ENABLE_CUSTOM_TLS 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_SSI
|
||||
#define MG_ENABLE_SSI 1
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_IPV6
|
||||
#define MG_ENABLE_IPV6 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_LOG
|
||||
#define MG_ENABLE_LOG 1
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_MD5
|
||||
#define MG_ENABLE_MD5 0
|
||||
#endif
|
||||
|
||||
// Set MG_ENABLE_WINSOCK=0 for Win32 builds with external IP stack (like LWIP)
|
||||
#ifndef MG_ENABLE_WINSOCK
|
||||
#define MG_ENABLE_WINSOCK 1
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_DIRLIST
|
||||
#define MG_ENABLE_DIRLIST 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_CUSTOM_RANDOM
|
||||
#define MG_ENABLE_CUSTOM_RANDOM 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_PACKED_FS
|
||||
#define MG_ENABLE_PACKED_FS 0
|
||||
#endif
|
||||
|
||||
// Granularity of the send/recv IO buffer growth
|
||||
#ifndef MG_IO_SIZE
|
||||
#define MG_IO_SIZE 2048
|
||||
#endif
|
||||
|
||||
// Maximum size of the recv IO buffer
|
||||
#ifndef MG_MAX_RECV_BUF_SIZE
|
||||
#define MG_MAX_RECV_BUF_SIZE (3 * 1024 * 1024)
|
||||
#endif
|
||||
|
||||
#ifndef MG_MAX_HTTP_HEADERS
|
||||
#define MG_MAX_HTTP_HEADERS 40
|
||||
#endif
|
||||
|
||||
#ifndef MG_HTTP_INDEX
|
||||
#define MG_HTTP_INDEX "index.html"
|
||||
#endif
|
||||
|
||||
#ifndef MG_PATH_MAX
|
||||
#define MG_PATH_MAX PATH_MAX
|
||||
#endif
|
||||
|
||||
#ifndef MG_SOCK_LISTEN_BACKLOG_SIZE
|
||||
#define MG_SOCK_LISTEN_BACKLOG_SIZE 128
|
||||
#endif
|
||||
|
||||
|
||||
#define MG_ARCH_CUSTOM 0
|
||||
#define MG_ARCH_UNIX 1
|
||||
#define MG_ARCH_WIN32 2
|
||||
@@ -205,11 +129,6 @@ static __inline struct tm *localtime_r(time_t *t, struct tm *tm) {
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
#undef MG_PATH_MAX
|
||||
#undef MG_ENABLE_DIRLIST
|
||||
|
||||
#define MG_DIRSEP '/'
|
||||
#define MG_INT64_FMT "%lld"
|
||||
#define MG_PATH_MAX 128
|
||||
#define MG_ENABLE_DIRLIST 1
|
||||
|
||||
@@ -237,11 +156,6 @@ static __inline struct tm *localtime_r(time_t *t, struct tm *tm) {
|
||||
|
||||
#include <esp_system.h>
|
||||
|
||||
#undef MG_PATH_MAX
|
||||
#undef MG_ENABLE_DIRLIST
|
||||
|
||||
#define MG_DIRSEP '/'
|
||||
#define MG_INT64_FMT "%lld"
|
||||
#define MG_PATH_MAX 128
|
||||
#define MG_ENABLE_DIRLIST 1
|
||||
|
||||
@@ -321,9 +235,6 @@ static inline void *mg_calloc(int cnt, size_t size) {
|
||||
#include <FreeRTOS_Sockets.h>
|
||||
#include <task.h>
|
||||
|
||||
#define MG_INT64_FMT "%lld"
|
||||
#define MG_DIRSEP '/'
|
||||
|
||||
// Why FreeRTOS-TCP did not implement a clean BSD API, but its own thing
|
||||
// with FreeRTOS_ prefix, is beyond me
|
||||
#define IPPROTO_TCP FREERTOS_IPPROTO_TCP
|
||||
@@ -418,9 +329,7 @@ struct timeval {
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define MG_DIRSEP '/'
|
||||
#define MG_INT64_FMT "%" PRId64
|
||||
#undef MG_ENABLE_DIRLIST
|
||||
#define MG_ENABLE_DIRLIST 1
|
||||
|
||||
#endif
|
||||
@@ -525,6 +434,102 @@ static __inline struct tm *localtime_r(time_t *t, struct tm *tm) {
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef MG_ENABLE_SOCKET
|
||||
#define MG_ENABLE_SOCKET 1
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_MBEDTLS
|
||||
#define MG_ENABLE_MBEDTLS 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_OPENSSL
|
||||
#define MG_ENABLE_OPENSSL 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_CUSTOM_TLS
|
||||
#define MG_ENABLE_CUSTOM_TLS 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_SSI
|
||||
#define MG_ENABLE_SSI 1
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_IPV6
|
||||
#define MG_ENABLE_IPV6 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_LOG
|
||||
#define MG_ENABLE_LOG 1
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_MD5
|
||||
#define MG_ENABLE_MD5 0
|
||||
#endif
|
||||
|
||||
// Set MG_ENABLE_WINSOCK=0 for Win32 builds with external IP stack (like LWIP)
|
||||
#ifndef MG_ENABLE_WINSOCK
|
||||
#define MG_ENABLE_WINSOCK 1
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_DIRLIST
|
||||
#define MG_ENABLE_DIRLIST 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_CUSTOM_RANDOM
|
||||
#define MG_ENABLE_CUSTOM_RANDOM 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_PACKED_FS
|
||||
#define MG_ENABLE_PACKED_FS 0
|
||||
#endif
|
||||
|
||||
// Granularity of the send/recv IO buffer growth
|
||||
#ifndef MG_IO_SIZE
|
||||
#define MG_IO_SIZE 2048
|
||||
#endif
|
||||
|
||||
// Maximum size of the recv IO buffer
|
||||
#ifndef MG_MAX_RECV_BUF_SIZE
|
||||
#define MG_MAX_RECV_BUF_SIZE (3 * 1024 * 1024)
|
||||
#endif
|
||||
|
||||
#ifndef MG_MAX_HTTP_HEADERS
|
||||
#define MG_MAX_HTTP_HEADERS 40
|
||||
#endif
|
||||
|
||||
#ifndef MG_HTTP_INDEX
|
||||
#define MG_HTTP_INDEX "index.html"
|
||||
#endif
|
||||
|
||||
#ifndef MG_PATH_MAX
|
||||
#ifdef PATH_MAX
|
||||
#define MG_PATH_MAX PATH_MAX
|
||||
#else
|
||||
#define MG_PATH_MAX 128
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef MG_SOCK_LISTEN_BACKLOG_SIZE
|
||||
#define MG_SOCK_LISTEN_BACKLOG_SIZE 128
|
||||
#endif
|
||||
|
||||
#ifndef MG_DIRSEP
|
||||
#define MG_DIRSEP '/'
|
||||
#endif
|
||||
|
||||
#ifndef MG_INT64_FMT
|
||||
#define MG_INT64_FMT "%lld"
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_FILE
|
||||
#if defined(FOPEN_MAX)
|
||||
#define MG_ENABLE_FILE 1
|
||||
#else
|
||||
#define MG_ENABLE_FILE 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
@@ -17,11 +17,6 @@
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
#undef MG_PATH_MAX
|
||||
#undef MG_ENABLE_DIRLIST
|
||||
|
||||
#define MG_DIRSEP '/'
|
||||
#define MG_INT64_FMT "%lld"
|
||||
#define MG_PATH_MAX 128
|
||||
#define MG_ENABLE_DIRLIST 1
|
||||
|
||||
|
||||
@@ -21,11 +21,6 @@
|
||||
|
||||
#include <esp_system.h>
|
||||
|
||||
#undef MG_PATH_MAX
|
||||
#undef MG_ENABLE_DIRLIST
|
||||
|
||||
#define MG_DIRSEP '/'
|
||||
#define MG_INT64_FMT "%lld"
|
||||
#define MG_PATH_MAX 128
|
||||
#define MG_ENABLE_DIRLIST 1
|
||||
|
||||
|
||||
@@ -19,9 +19,6 @@
|
||||
#include <FreeRTOS_Sockets.h>
|
||||
#include <task.h>
|
||||
|
||||
#define MG_INT64_FMT "%lld"
|
||||
#define MG_DIRSEP '/'
|
||||
|
||||
// Why FreeRTOS-TCP did not implement a clean BSD API, but its own thing
|
||||
// with FreeRTOS_ prefix, is beyond me
|
||||
#define IPPROTO_TCP FREERTOS_IPPROTO_TCP
|
||||
|
||||
@@ -29,9 +29,7 @@
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define MG_DIRSEP '/'
|
||||
#define MG_INT64_FMT "%" PRId64
|
||||
#undef MG_ENABLE_DIRLIST
|
||||
#define MG_ENABLE_DIRLIST 1
|
||||
|
||||
#endif
|
||||
@@ -68,9 +68,29 @@
|
||||
#endif
|
||||
|
||||
#ifndef MG_PATH_MAX
|
||||
#ifdef PATH_MAX
|
||||
#define MG_PATH_MAX PATH_MAX
|
||||
#else
|
||||
#define MG_PATH_MAX 128
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef MG_SOCK_LISTEN_BACKLOG_SIZE
|
||||
#define MG_SOCK_LISTEN_BACKLOG_SIZE 128
|
||||
#endif
|
||||
|
||||
#ifndef MG_DIRSEP
|
||||
#define MG_DIRSEP '/'
|
||||
#endif
|
||||
|
||||
#ifndef MG_INT64_FMT
|
||||
#define MG_INT64_FMT "%lld"
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_FILE
|
||||
#if defined(FOPEN_MAX)
|
||||
#define MG_ENABLE_FILE 1
|
||||
#else
|
||||
#define MG_ENABLE_FILE 0
|
||||
#endif
|
||||
#endif
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
#include "fs.h"
|
||||
|
||||
#if defined(FOPEN_MAX)
|
||||
#if MG_ENABLE_FILE
|
||||
static int p_stat(const char *path, size_t *size, time_t *mtime) {
|
||||
#ifdef _WIN32
|
||||
struct _stati64 st;
|
||||
@@ -176,9 +176,9 @@ static size_t p_write(void *fp, const void *buf, size_t len) {
|
||||
}
|
||||
|
||||
static size_t p_seek(void *fp, size_t offset) {
|
||||
#if (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) || \
|
||||
(defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || \
|
||||
(defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600)
|
||||
#if (defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64) || \
|
||||
(defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || \
|
||||
(defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600)
|
||||
fseeko((FILE *) fp, (off_t) offset, SEEK_SET);
|
||||
#else
|
||||
fseek((FILE *) fp, (long) offset, SEEK_SET);
|
||||
|
||||
@@ -378,6 +378,7 @@ char *mg_http_etag(char *buf, size_t len, size_t size, time_t mtime) {
|
||||
return buf;
|
||||
}
|
||||
|
||||
#if MG_ENABLE_FILE
|
||||
int mg_http_upload(struct mg_connection *c, struct mg_http_message *hm,
|
||||
const char *dir) {
|
||||
char offset[40] = "", name[200] = "", path[256];
|
||||
@@ -403,6 +404,7 @@ int mg_http_upload(struct mg_connection *c, struct mg_http_message *hm,
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void static_cb(struct mg_connection *c, int ev, void *ev_data,
|
||||
void *fn_data) {
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
#if MG_ENABLE_LOG
|
||||
static void mg_log_stdout(const void *buf, size_t len, void *userdata) {
|
||||
(void) userdata;
|
||||
#if MG_ENABLE_FILE
|
||||
fwrite(buf, 1, len, stdout);
|
||||
#endif
|
||||
}
|
||||
|
||||
static const char *s_spec = "2";
|
||||
|
||||
+4
-2
@@ -6,6 +6,7 @@
|
||||
#include <mach/mach_time.h>
|
||||
#endif
|
||||
|
||||
#if MG_ENABLE_FILE
|
||||
char *mg_file_read(const char *path, size_t *sizep) {
|
||||
FILE *fp;
|
||||
char *data = NULL;
|
||||
@@ -47,6 +48,7 @@ bool mg_file_write(const char *path, const void *buf, size_t len) {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool mg_file_printf(const char *path, const char *fmt, ...) {
|
||||
char tmp[256], *buf = tmp;
|
||||
@@ -355,8 +357,8 @@ unsigned long mg_millis(void) {
|
||||
uint64_t ticks = mach_absolute_time();
|
||||
static mach_timebase_info_data_t timebase;
|
||||
mach_timebase_info(&timebase);
|
||||
double ticks_to_nanos = (double)timebase.numer / timebase.denom;
|
||||
uint64_t uptime_nanos = (uint64_t)(ticks_to_nanos * ticks);
|
||||
double ticks_to_nanos = (double) timebase.numer / timebase.denom;
|
||||
uint64_t uptime_nanos = (uint64_t) (ticks_to_nanos * ticks);
|
||||
return (unsigned long) (uptime_nanos / 1000000);
|
||||
#else
|
||||
struct timespec ts;
|
||||
|
||||
@@ -15,9 +15,5 @@
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define MG_DIRSEP '/'
|
||||
#define MG_INT64_FMT "%lld"
|
||||
#undef MG_PATH_MAX
|
||||
#define MG_PATH_MAX 100
|
||||
#undef MG_ENABLE_SOCKET
|
||||
#define MG_ENABLE_SOCKET 0
|
||||
Reference in new issue
Block a user