diff --git a/examples/ESP8266_RTOS/user/Makefile b/examples/ESP8266_RTOS/user/Makefile index 532f357ac7dcaecc5d2b003caba2e73456f0013f..cbfdd4d07b7834469fbaf17e3a41254ce16c3a91 100644 --- a/examples/ESP8266_RTOS/user/Makefile +++ b/examples/ESP8266_RTOS/user/Makefile @@ -25,7 +25,6 @@ endif # DEFINES += -DCS_PLATFORM=3 \ -DMG_NO_BSD_SOCKETS=1 \ - -DMG_DISABLE_FILESYSTEM=1 \ -DRTOS_SDK -DMG_LWIP -DLWIP_TIMEVAL_PRIVATE=0 \ -DMG_INTERNAL= diff --git a/mongoose.c b/mongoose.c index 08ed1d2d1933b4d495edb52744ca9f661c37ecc8..69f4faf16c8a686498a5c26f7cb7cc95fcd63c25 100644 --- a/mongoose.c +++ b/mongoose.c @@ -45,9 +45,7 @@ #ifdef PICOTCP #define NO_LIBC -#define MG_DISABLE_FILESYSTEM #define MG_DISABLE_POPEN -#define MG_DISABLE_DIRECTORY_LISTING #define MG_DISABLE_SOCKETPAIR #define MG_DISABLE_PFS #endif @@ -73,11 +71,13 @@ MG_INTERNAL void mg_remove_conn(struct mg_connection *c); MG_INTERNAL struct mg_connection *mg_create_connection( struct mg_mgr *mgr, mg_event_handler_t callback, struct mg_add_sock_opts opts); -#if !MG_DISABLE_FILESYSTEM +#if MG_ENABLE_FILESYSTEM MG_INTERNAL int mg_uri_to_local_path(struct http_message *hm, const struct mg_serve_http_opts *opts, char **local_path, struct mg_str *remainder); +MG_INTERNAL time_t mg_parse_date_string(const char *datetime); +MG_INTERNAL int mg_is_not_modified(struct http_message *hm, cs_stat_t *st); #endif #ifdef _WIN32 /* Retur value is the same as for MultiByteToWideChar. */ @@ -99,11 +99,6 @@ MG_INTERNAL size_t mg_handle_chunked(struct mg_connection *nc, struct http_message *hm, char *buf, size_t blen); -#if !MG_DISABLE_FILESYSTEM -MG_INTERNAL time_t mg_parse_date_string(const char *datetime); -MG_INTERNAL int mg_is_not_modified(struct http_message *hm, cs_stat_t *st); -#endif - struct ctl_msg { mg_event_handler_t callback; char message[MG_CTL_MSG_MESSAGE_SIZE]; @@ -3880,7 +3875,7 @@ struct mg_http_multipart_stream { }; struct mg_http_proto_data { -#if !MG_DISABLE_FILESYSTEM +#if MG_ENABLE_FILESYSTEM struct mg_http_proto_data_file file; #endif #if MG_ENABLE_CGI @@ -3916,7 +3911,7 @@ static void mg_http_free_proto_data_mp_stream( } #endif -#if !MG_DISABLE_FILESYSTEM +#if MG_ENABLE_FILESYSTEM static void mg_http_free_proto_data_file(struct mg_http_proto_data_file *d) { if (d != NULL) { if (d->fp != NULL) { @@ -3942,7 +3937,7 @@ static void mg_http_free_proto_data_endpoints(struct mg_http_endpoint **ep) { static void mg_http_conn_destructor(void *proto_data) { struct mg_http_proto_data *pd = (struct mg_http_proto_data *) proto_data; -#if !MG_DISABLE_FILESYSTEM +#if MG_ENABLE_FILESYSTEM mg_http_free_proto_data_file(&pd->file); #endif #if MG_ENABLE_CGI @@ -3955,7 +3950,7 @@ static void mg_http_conn_destructor(void *proto_data) { free(proto_data); } -#if !MG_DISABLE_FILESYSTEM +#if MG_ENABLE_FILESYSTEM #define MIME_ENTRY(_ext, _type) \ { _ext, sizeof(_ext) - 1, _type } @@ -4482,7 +4477,7 @@ static void mg_ws_handshake(struct mg_connection *nc, #endif /* MG_DISABLE_HTTP_WEBSOCKET */ -#if !MG_DISABLE_FILESYSTEM +#if MG_ENABLE_FILESYSTEM static void mg_http_transfer_file_data(struct mg_connection *nc) { struct mg_http_proto_data *pd = mg_http_get_proto_data(nc); char buf[MG_MAX_HTTP_SEND_MBUF]; @@ -4532,7 +4527,7 @@ static void mg_http_transfer_file_data(struct mg_connection *nc) { } #endif } -#endif /* MG_DISABLE_FILESYSTEM */ +#endif /* MG_ENABLE_FILESYSTEM */ /* * Parse chunked-encoded buffer. Return 0 if the buffer is not encoded, or @@ -4736,7 +4731,7 @@ void mg_http_handler(struct mg_connection *nc, int ev, void *ev_data) { } } -#if !MG_DISABLE_FILESYSTEM +#if MG_ENABLE_FILESYSTEM if (pd->file.fp != NULL) { mg_http_transfer_file_data(nc); } @@ -5380,12 +5375,7 @@ void mg_send_head(struct mg_connection *c, int status_code, mg_send(c, "\r\n", 2); } -#if MG_DISABLE_FILESYSTEM -void mg_serve_http(struct mg_connection *nc, struct http_message *hm, - struct mg_serve_http_opts opts) { - mg_send_head(nc, 501, 0, NULL); -} -#else +#if MG_ENABLE_FILESYSTEM static void mg_http_send_error(struct mg_connection *nc, int code, const char *reason) { if (!reason) reason = ""; @@ -5883,7 +5873,7 @@ int mg_http_parse_header(struct mg_str *hdr, const char *var_name, char *buf, return len; } -#if !MG_DISABLE_FILESYSTEM +#if MG_ENABLE_FILESYSTEM static int mg_is_file_hidden(const char *path, const struct mg_serve_http_opts *opts, int exclude_specials) { @@ -6045,7 +6035,7 @@ static int mg_is_authorized(struct http_message *hm, const char *path, } #endif -#if !MG_DISABLE_DIRECTORY_LISTING +#if MG_ENABLE_DIRECTORY_LISTING static size_t mg_url_encode(const char *src, size_t s_len, char *dst, size_t dst_len) { static const char *dont_escape = "._-$,;~()/"; @@ -6198,7 +6188,7 @@ static void mg_send_directory_listing(struct mg_connection *nc, const char *dir, /* TODO(rojer): Remove when cesanta/dev/issues/197 is fixed. */ nc->flags |= MG_F_SEND_AND_CLOSE; } -#endif /* MG_DISABLE_DIRECTORY_LISTING */ +#endif /* MG_ENABLE_DIRECTORY_LISTING */ /* * Given a directory path, find one of the files specified in the @@ -6578,7 +6568,7 @@ MG_INTERNAL void mg_send_http_file(struct mg_connection *nc, char *path, } else if (!mg_vcmp(&hm->method, "OPTIONS")) { mg_http_send_options(nc); } else if (is_directory && index_file == NULL) { -#if !MG_DISABLE_DIRECTORY_LISTING +#if MG_ENABLE_DIRECTORY_LISTING if (strcmp(opts->enable_directory_listing, "yes") == 0) { mg_send_directory_listing(nc, path, hm, opts); } else { @@ -6654,7 +6644,7 @@ void mg_serve_http(struct mg_connection *nc, struct http_message *hm, } } -#endif /* MG_DISABLE_FILESYSTEM */ +#endif /* MG_ENABLE_FILESYSTEM */ /* returns 0 on success, -1 on error */ static int mg_http_common_url_parse(const char *url, const char *schema, @@ -7667,7 +7657,7 @@ int mg_casecmp(const char *s1, const char *s2) { return mg_ncasecmp(s1, s2, (size_t) ~0); } -#if !MG_DISABLE_FILESYSTEM +#if MG_ENABLE_FILESYSTEM int mg_stat(const char *path, cs_stat_t *st) { #ifdef _WIN32 wchar_t wpath[MAX_PATH_SIZE]; @@ -7830,7 +7820,7 @@ void mg_hexdump_connection(struct mg_connection *nc, const char *path, fp = stdout; } else if (strcmp(path, "--") == 0) { fp = stderr; -#if !MG_DISABLE_FILESYSTEM +#if MG_ENABLE_FILESYSTEM } else { fp = fopen(path, "a"); #endif @@ -9019,7 +9009,7 @@ static int mg_get_ip_address_of_nameserver(char *name, size_t name_len) { } RegCloseKey(hKey); } -#elif !MG_DISABLE_FILESYSTEM +#elif MG_ENABLE_FILESYSTEM FILE *fp; char line[512]; @@ -9045,7 +9035,7 @@ static int mg_get_ip_address_of_nameserver(char *name, size_t name_len) { } int mg_resolve_from_hosts_file(const char *name, union socket_address *usa) { -#if !MG_DISABLE_FILESYSTEM +#if MG_ENABLE_FILESYSTEM /* TODO(mkm) cache /etc/hosts */ FILE *fp; char line[1024]; @@ -9075,6 +9065,9 @@ int mg_resolve_from_hosts_file(const char *name, union socket_address *usa) { } fclose(fp); +#else + (void) name; + (void) usa; #endif return -1; diff --git a/mongoose.h b/mongoose.h index 4b9206124e88ebbc6475c3cb42e8b57cdcf6d9db..0c8e04d126eb7ecc446f32b597bf83079d19a063 100644 --- a/mongoose.h +++ b/mongoose.h @@ -245,6 +245,14 @@ typedef struct _stati64 cs_stat_t; #define CS_ENABLE_STDIO 1 #endif +#ifndef MG_ENABLE_DIRECTORY_LISTING +#define MG_ENABLE_DIRECTORY_LISTING 1 +#endif + +#ifndef MG_ENABLE_FILESYSTEM +#define MG_ENABLE_FILESYSTEM 1 +#endif + #endif /* CS_PLATFORM == CS_P_WINDOWS */ #endif /* CS_COMMON_PLATFORMS_PLATFORM_WINDOWS_H_ */ #ifdef MG_MODULE_LINES @@ -351,6 +359,14 @@ typedef struct stat cs_stat_t; #define CS_ENABLE_STDIO 1 #endif +#ifndef MG_ENABLE_DIRECTORY_LISTING +#define MG_ENABLE_DIRECTORY_LISTING 1 +#endif + +#ifndef MG_ENABLE_FILESYSTEM +#define MG_ENABLE_FILESYSTEM 1 +#endif + #endif /* CS_PLATFORM == CS_P_UNIX */ #endif /* CS_COMMON_PLATFORMS_PLATFORM_UNIX_H_ */ #ifdef MG_MODULE_LINES @@ -445,9 +461,6 @@ void mg_lwip_set_keepalive_params(struct mg_connection *nc, int idle, #define MG_DISABLE_SOCKETPAIR 1 #define MG_DISABLE_SYNC_RESOLVER 1 #define MG_DISABLE_POPEN 1 -#define MG_DISABLE_DAV 1 -#define MG_DISABLE_DIRECTORY_LISTING 1 -#define MG_DISABLE_FILESYSTEM 1 /* * CC3100 SDK and STM32 SDK include headers w/out path, just like @@ -504,10 +517,10 @@ int inet_pton(int af, const char *src, void *dst); #define MG_DISABLE_SOCKETPAIR 1 #define MG_DISABLE_SYNC_RESOLVER 1 #define MG_DISABLE_POPEN 1 + /* Only SPIFFS supports directories, SLFS does not. */ -#ifndef CC3200_FS_SPIFFS -#define MG_DISABLE_DAV 1 -#define MG_DISABLE_DIRECTORY_LISTING 1 +#if defined(CC3200_FS_SPIFFS) && !defined(MG_ENABLE_DIRECTORY_LISTING) +#define MG_ENABLE_DIRECTORY_LISTING 1 #endif /* Amalgamated: #include "common/platforms/simplelink/cs_simplelink.h" */ @@ -598,6 +611,10 @@ struct dirent *readdir(DIR *dir); #define MG_FS_SLFS #endif +#if (defined(CC3200_FS_SPIFFS) || defined(CC3200_FS_SLFS)) && !defined(MG_ENABLE_FILESYSTEM) +#define MG_ENABLE_FILESYSTEM 1 +#endif + #ifndef CS_ENABLE_STDIO #define CS_ENABLE_STDIO 1 #endif @@ -638,7 +655,6 @@ struct dirent *readdir(DIR *dir); #define MG_DISABLE_SYNC_RESOLVER 1 #define MG_DISABLE_POPEN 1 #define MG_DISABLE_DAV 1 -#define MG_DISABLE_DIRECTORY_LISTING 1 /* Amalgamated: #include "common/platforms/simplelink/cs_simplelink.h" */ @@ -709,6 +725,10 @@ int _stat(const char *pathname, struct stat *st); #define CS_ENABLE_STDIO 1 #endif +#if (defined(CC3200_FS_SPIFFS) || defined(CC3200_FS_SLFS)) && !defined(MG_ENABLE_FILESYSTEM) +#define MG_ENABLE_FILESYSTEM 1 +#endif + #ifdef __cplusplus } #endif @@ -1186,18 +1206,10 @@ const char *c_strnstr(const char *s, const char *find, size_t slen); #ifndef CS_MONGOOSE_SRC_FEATURES_H_ #define CS_MONGOOSE_SRC_FEATURES_H_ -#ifndef MG_DISABLE_DIRECTORY_LISTING -#define MG_DISABLE_DIRECTORY_LISTING 0 -#endif - #ifndef MG_DISABLE_DNS #define MG_DISABLE_DNS 0 #endif -#ifndef MG_DISABLE_FILESYSTEM -#define MG_DISABLE_FILESYSTEM 0 -#endif - #ifndef MG_DISABLE_HTTP_DIGEST_AUTH #define MG_DISABLE_HTTP_DIGEST_AUTH 0 #endif @@ -1258,6 +1270,10 @@ const char *c_strnstr(const char *s, const char *find, size_t slen); #define MG_ENABLE_DEBUG 0 #endif +#ifndef MG_ENABLE_DIRECTORY_LISTING +#define MG_ENABLE_DIRECTORY_LISTING 0 +#endif + #ifndef MG_ENABLE_DNS_SERVER #define MG_ENABLE_DNS_SERVER 0 #endif @@ -1266,6 +1282,10 @@ const char *c_strnstr(const char *s, const char *find, size_t slen); #define MG_ENABLE_FAKE_DAVLOCK 0 #endif +#ifndef MG_ENABLE_FILESYSTEM +#define MG_ENABLE_FILESYSTEM 0 +#endif + #ifndef MG_ENABLE_GETADDRINFO #define MG_ENABLE_GETADDRINFO 0 #endif @@ -1318,12 +1338,6 @@ const char *c_strnstr(const char *s, const char *find, size_t slen); #define CS_ENABLE_DEBUG 1 #endif -/* All of the below features depend on filesystem access, disable them. */ -#if MG_DISABLE_FILESYSTEM -#undef MG_DISABLE_DIRECTORY_LISTING -#define MG_DISABLE_DIRECTORY_LISTING 1 -#endif /* MG_DISABLE_FILESYSTEM */ - #ifdef MG_NO_BSD_SOCKETS #undef MG_DISABLE_SYNC_RESOLVER #define MG_DISABLE_SYNC_RESOLVER 1 @@ -2108,7 +2122,7 @@ int mg_base64_decode(const unsigned char *s, int len, char *dst); */ void mg_base64_encode(const unsigned char *src, int src_len, char *dst); -#if !MG_DISABLE_FILESYSTEM +#if MG_ENABLE_FILESYSTEM /* * Performs a 64-bit `stat()` call against a given file. * @@ -2135,7 +2149,7 @@ FILE *mg_fopen(const char *path, const char *mode); * Return value is the same as for the `open()` syscall. */ int mg_open(const char *path, int flag, int mode); -#endif /* MG_DISABLE_FILESYSTEM */ +#endif /* MG_ENABLE_FILESYSTEM */ #if MG_ENABLE_THREADS /* @@ -2683,6 +2697,7 @@ size_t mg_parse_multipart(const char *buf, size_t buf_len, char *var_name, int mg_get_http_var(const struct mg_str *buf, const char *name, char *dst, size_t dst_len); +#if MG_ENABLE_FILESYSTEM /* * This structure defines how `mg_serve_http()` works. * Best practice is to set only required settings, and leave the rest as NULL. @@ -2884,6 +2899,7 @@ void mg_serve_http(struct mg_connection *nc, struct http_message *hm, void mg_http_serve_file(struct mg_connection *nc, struct http_message *hm, const char *path, const struct mg_str mime_type, const struct mg_str extra_headers); +#endif /* MG_ENABLE_FILESYSTEM */ /* * Registers a callback for a specified http endpoint