diff --git a/docs/c-api/net.h/struct_mg_connection.md b/docs/c-api/net.h/struct_mg_connection.md index 682aa85b9f16130588f36ce506d12246cc420d46..805675c51cbba637de5f0ce7ee2dd00d9804d031 100644 --- a/docs/c-api/net.h/struct_mg_connection.md +++ b/docs/c-api/net.h/struct_mg_connection.md @@ -15,7 +15,7 @@ signature: | struct mbuf recv_mbuf; /* Received data */ struct mbuf send_mbuf; /* Data scheduled for sending */ #if MG_ENABLE_SSL - #if !defined(MG_SOCKET_SIMPLELINK) + #if MG_NET_IF != MG_NET_IF_SIMPLELINK SSL *ssl; SSL_CTX *ssl_ctx; #else diff --git a/mongoose.c b/mongoose.c index de1c499ed8ad85886a04126c561524097424346c..eff19e317d620cb4424830c6e16204074324d238 100644 --- a/mongoose.c +++ b/mongoose.c @@ -1857,7 +1857,7 @@ static void mg_destroy_conn(struct mg_connection *conn, int destroy_if) { if (conn->proto_data != NULL && conn->proto_data_destructor != NULL) { conn->proto_data_destructor(conn->proto_data); } -#if MG_ENABLE_SSL && !defined(MG_SOCKET_SIMPLELINK) +#if MG_ENABLE_SSL && MG_NET_IF == MG_NET_IF_SOCKET if (conn->ssl != NULL) SSL_free(conn->ssl); if (conn->ssl_ctx != NULL) SSL_CTX_free(conn->ssl_ctx); #endif @@ -1894,7 +1894,7 @@ void mg_mgr_init(struct mg_mgr *m, void *user_data) { signal(SIGPIPE, SIG_IGN); #endif -#if MG_ENABLE_SSL && !defined(MG_SOCKET_SIMPLELINK) +#if MG_ENABLE_SSL && MG_NET_IF == MG_NET_IF_SOCKET { static int init_done; if (!init_done) { @@ -2145,7 +2145,7 @@ MG_INTERNAL int mg_parse_address(const char *str, union socket_address *sa, #if MG_ENABLE_SSL -#ifndef MG_SOCKET_SIMPLELINK +#if MG_NET_IF != MG_NET_IF_SIMPLELINK /* * Certificate generation script is at * https://github.com/cesanta/mongoose/blob/master/scripts/generate_ssl_certificates.sh @@ -2330,7 +2330,7 @@ const char *mg_set_ssl(struct mg_connection *nc, const char *cert, #else const char *mg_set_ssl2(struct mg_connection *nc, const char *cert, const char *key, const char *ca_cert); -#endif /* MG_SOCKET_SIMPLELINK */ +#endif /* MG_NET_IF == MG_NET_IF_SIMPLELINK */ #endif /* MG_ENABLE_SSL */ @@ -2542,7 +2542,7 @@ static void mg_set_ssl_server_name(struct mg_connection *nc, DBG(("%p '%s'", nc, server_name)); #ifdef SSL_KRYPTON SSL_CTX_kr_set_verify_name(nc->ssl_ctx, server_name); -#elif defined(MG_SOCKET_SIMPLELINK) +#elif MG_NET_IF == MG_NET_IF_SIMPLELINK nc->ssl_server_name = strdup(server_name); #else /* TODO(rojer): Implement server name verification on OpenSSL. */ @@ -2823,7 +2823,7 @@ double mg_time(void) { * All rights reserved */ -#if !MG_DISABLE_SOCKET_IF && !defined(MG_SOCKET_SIMPLELINK) +#if MG_NET_IF == MG_NET_IF_SOCKET /* Amalgamated: #include "mongoose/src/internal.h" */ /* Amalgamated: #include "mongoose/src/util.h" */ @@ -3526,7 +3526,7 @@ void mg_if_get_conn_addr(struct mg_connection *nc, int remote, mg_sock_get_addr(nc->sock, remote, sa); } -#endif /* !MG_DISABLE_SOCKET_IF && !defined(MG_SOCKET_SIMPLELINK) */ +#endif /* MG_NET_IF == MG_NET_IF_SOCKET */ #ifdef MG_MODULE_LINES #line 1 "mongoose/src/multithreading.c" #endif @@ -10264,7 +10264,7 @@ void fs_slfs_set_new_file_size(const char *name, size_t size) { * All rights reserved */ -#if defined(MG_SOCKET_SIMPLELINK) && \ +#if MG_NET_IF == MG_NET_IF_SIMPLELINK && \ (defined(MG_FS_SLFS) || defined(MG_FS_SPIFFS)) #include <errno.h> @@ -10650,7 +10650,7 @@ int sl_fs_init(void) { return ret; } -#endif /* defined(MG_SOCKET_SIMPLELINK) && (defined(MG_FS_SLFS) || \ +#endif /* MG_NET_IF == MG_NET_IF_SIMPLELINK && (defined(MG_FS_SLFS) || \ defined(MG_FS_SPIFFS)) */ #ifdef MG_MODULE_LINES #line 1 "common/platforms/simplelink/sl_socket.c" @@ -10660,7 +10660,7 @@ int sl_fs_init(void) { * All rights reserved */ -#ifdef MG_SOCKET_SIMPLELINK +#if MG_NET_IF == MG_NET_IF_SIMPLELINK #include <errno.h> #include <stdio.h> @@ -10702,11 +10702,11 @@ int inet_pton(int af, const char *src, void *dst) { return 1; } -#endif /* CS_COMMON_PLATFORMS_SIMPLELINK_SL_SOCKET_C_ */ +#endif /* MG_NET_IF == MG_NET_IF_SIMPLELINK */ #ifdef MG_MODULE_LINES #line 1 "common/platforms/simplelink/sl_mg_task.c" #endif -#if defined(MG_SOCKET_SIMPLELINK) && !defined(MG_SIMPLELINK_NO_OSI) +#if MG_NET_IF == MG_NET_IF_SIMPLELINK && !defined(MG_SIMPLELINK_NO_OSI) /* Amalgamated: #include "mg_task.h" */ @@ -10756,7 +10756,7 @@ void mg_run_in_task(void (*cb)(struct mg_mgr *mgr, void *arg), void *cb_arg) { osi_MsgQWrite(&s_mg_q, &msg, OSI_NO_WAIT); } -#endif /* defined(MG_SOCKET_SIMPLELINK) */ +#endif /* MG_NET_IF == MG_NET_IF_SIMPLELINK && !defined(MG_SIMPLELINK_NO_OSI) */ #ifdef MG_MODULE_LINES #line 1 "common/platforms/simplelink/sl_net_if.c" #endif @@ -10765,7 +10765,7 @@ void mg_run_in_task(void (*cb)(struct mg_mgr *mgr, void *arg), void *cb_arg) { * All rights reserved */ -#if !MG_DISABLE_SOCKET_IF && defined(MG_SOCKET_SIMPLELINK) +#if MG_NET_IF == MG_NET_IF_SIMPLELINK /* Amalgamated: #include "mongoose/src/internal.h" */ /* Amalgamated: #include "mongoose/src/util.h" */ @@ -11266,7 +11266,7 @@ void sl_restart_cb(struct mg_mgr *mgr) { } } -#endif /* !MG_DISABLE_SOCKET_IF && defined(MG_SOCKET_SIMPLELINK) */ +#endif /* MG_NET_IF == MG_NET_IF_SIMPLELINK */ #ifdef MG_MODULE_LINES #line 1 "common/platforms/lwip/mg_lwip_net_if.h" #endif @@ -11278,7 +11278,7 @@ void sl_restart_cb(struct mg_mgr *mgr) { #ifndef CS_COMMON_PLATFORMS_LWIP_MG_NET_IF_LWIP_H_ #define CS_COMMON_PLATFORMS_LWIP_MG_NET_IF_LWIP_H_ -#ifdef MG_NET_IF_LWIP +#if MG_NET_IF == MG_NET_IF_LWIP_LOW_LEVEL #include <inttypes.h> @@ -11307,7 +11307,7 @@ void mg_lwip_post_signal(enum mg_sig_type sig, struct mg_connection *nc); /* To be implemented by the platform. */ void mg_lwip_mgr_schedule_poll(struct mg_mgr *mgr); -#endif /* MG_NET_IF_LWIP */ +#endif /* MG_NET_IF == MG_NET_IF_LWIP_LOW_LEVEL */ #endif /* CS_COMMON_PLATFORMS_LWIP_MG_NET_IF_LWIP_H_ */ #ifdef MG_MODULE_LINES @@ -11318,7 +11318,7 @@ void mg_lwip_mgr_schedule_poll(struct mg_mgr *mgr); * All rights reserved */ -#ifdef MG_NET_IF_LWIP +#if MG_NET_IF == MG_NET_IF_LWIP_LOW_LEVEL #include <lwip/pbuf.h> #include <lwip/tcp.h> @@ -11769,7 +11769,7 @@ void mg_sock_set(struct mg_connection *nc, sock_t sock) { nc->sock = sock; } -#endif /* MG_NET_IF_LWIP */ +#endif /* MG_NET_IF == MG_NET_IF_LWIP_LOW_LEVEL */ #ifdef MG_MODULE_LINES #line 1 "common/platforms/lwip/mg_lwip_ev_mgr.c" #endif @@ -11778,7 +11778,7 @@ void mg_sock_set(struct mg_connection *nc, sock_t sock) { * All rights reserved */ -#ifdef MG_NET_IF_LWIP +#if MG_NET_IF == MG_NET_IF_LWIP_LOW_LEVEL #ifndef MG_SIG_QUEUE_LEN #define MG_SIG_QUEUE_LEN 16 @@ -11946,7 +11946,7 @@ uint32_t mg_lwip_get_poll_delay_ms(struct mg_mgr *mgr) { return timeout_ms; } -#endif /* MG_NET_IF_LWIP */ +#endif /* MG_NET_IF == MG_NET_IF_LWIP_LOW_LEVEL */ #ifdef MG_MODULE_LINES #line 1 "common/platforms/lwip/mg_lwip_ssl_krypton.c" #endif @@ -11955,7 +11955,7 @@ uint32_t mg_lwip_get_poll_delay_ms(struct mg_mgr *mgr) { * All rights reserved */ -#if defined(MG_NET_IF_LWIP) && defined(SSL_KRYPTON) +#if MG_NET_IF == MG_NET_IF_LWIP_LOW_LEVEL && defined(SSL_KRYPTON) /* Amalgamated: #include "common/cs_dbg.h" */ @@ -12117,7 +12117,7 @@ ssize_t kr_recv(int fd, void *buf, size_t len, int flags) { return len; } -#endif /* defined(MG_NET_IF_LWIP) && defined(SSL_KRYPTON) */ +#endif /* MG_NET_IF == MG_NET_IF_LWIP_LOW_LEVEL && defined(SSL_KRYPTON) */ #ifdef MG_MODULE_LINES #line 1 "common/platforms/wince/wince_libc.c" #endif diff --git a/mongoose.h b/mongoose.h index 0a8ecdd52eda25e13f09a14a1befd47a7206bb40..dbdc832923e8f6f94ff7b87b629aae2629d67983 100644 --- a/mongoose.h +++ b/mongoose.h @@ -75,6 +75,10 @@ #endif /* !defined(CS_PLATFORM) */ +#define MG_NET_IF_SOCKET 1 +#define MG_NET_IF_SIMPLELINK 2 +#define MG_NET_IF_LWIP_LOW_LEVEL 3 + /* Amalgamated: #include "common/platforms/platform_unix.h" */ /* Amalgamated: #include "common/platforms/platform_windows.h" */ /* Amalgamated: #include "common/platforms/platform_esp_lwip.h" */ @@ -270,6 +274,10 @@ typedef struct _stati64 cs_stat_t; #define MG_ENABLE_HTTP_CGI 1 #endif +#ifndef MG_NET_IF +#define MG_NET_IF MG_NET_IF_SOCKET +#endif + #endif /* CS_PLATFORM == CS_P_WINDOWS */ #endif /* CS_COMMON_PLATFORMS_PLATFORM_WINDOWS_H_ */ #ifdef MG_MODULE_LINES @@ -392,6 +400,10 @@ typedef struct stat cs_stat_t; #define MG_ENABLE_HTTP_CGI 1 #endif +#ifndef MG_NET_IF +#define MG_NET_IF MG_NET_IF_SOCKET +#endif + #endif /* CS_PLATFORM == CS_P_UNIX */ #endif /* CS_COMMON_PLATFORMS_PLATFORM_UNIX_H_ */ #ifdef MG_MODULE_LINES @@ -448,12 +460,14 @@ unsigned long os_random(void); #define random os_random #ifndef RTOS_SDK -#define MG_NET_IF_LWIP +#define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL struct mg_mgr; struct mg_connection; uint32_t mg_lwip_get_poll_delay_ms(struct mg_mgr *mgr); void mg_lwip_set_keepalive_params(struct mg_connection *nc, int idle, int interval, int count); +#else +#define MG_NET_IF MG_NET_IF_SOCKET #endif #ifndef CS_ENABLE_STDIO @@ -482,7 +496,7 @@ void mg_lwip_set_keepalive_params(struct mg_connection *nc, int idle, #include <string.h> #include <time.h> -#define MG_SOCKET_SIMPLELINK 1 +#define MG_NET_IF MG_NET_IF_SIMPLELINK #define MG_DISABLE_SYNC_RESOLVER 1 /* @@ -536,7 +550,7 @@ int inet_pton(int af, const char *src, void *dst); #include <sys/time.h> #endif -#define MG_SOCKET_SIMPLELINK 1 +#define MG_NET_IF MG_NET_IF_SIMPLELINK #define MG_DISABLE_SYNC_RESOLVER 1 /* Only SPIFFS supports directories, SLFS does not. */ @@ -671,7 +685,7 @@ struct dirent *readdir(DIR *dir); #include <sys/time.h> #endif -#define MG_SOCKET_SIMPLELINK 1 +#define MG_NET_IF MG_NET_IF_SIMPLELINK #define MG_DISABLE_SYNC_RESOLVER 1 /* Amalgamated: #include "common/platforms/simplelink/cs_simplelink.h" */ @@ -785,7 +799,7 @@ int _stat(const char *pathname, struct stat *st); #define CS_COMMON_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_ /* If simplelink.h is already included, all bets are off. */ -#if defined(MG_SOCKET_SIMPLELINK) && !defined(__SIMPLELINK_H__) +#if MG_NET_IF == MG_NET_IF_SIMPLELINK && !defined(__SIMPLELINK_H__) #include <stdbool.h> @@ -876,7 +890,7 @@ int sl_set_ssl_opts(struct mg_connection *nc); } #endif -#endif /* defined(MG_SOCKET_SIMPLELINK) && !defined(__SIMPLELINK_H__) */ +#endif /* MG_NET_IF == MG_NET_IF_SIMPLELINK && !defined(__SIMPLELINK_H__) */ #endif /* CS_COMMON_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_ */ #ifdef MG_MODULE_LINES @@ -1032,6 +1046,10 @@ typedef unsigned int* uintptr_t; #define MG_ENABLE_FILESYSTEM 1 #endif +#ifndef MG_NET_IF +#define MG_NET_IF MG_NET_IF_SOCKET +#endif + typedef struct _stati64 { uint32_t st_mtime; uint32_t st_size; @@ -1423,10 +1441,6 @@ const char *c_strnstr(const char *s, const char *find, size_t slen); #define MG_DISABLE_RESOLVER 0 #endif -#ifndef MG_DISABLE_SOCKET_IF -#define MG_DISABLE_SOCKET_IF 0 -#endif - #ifndef MG_DISABLE_SYNC_RESOLVER #define MG_DISABLE_SYNC_RESOLVER 0 #endif @@ -1523,6 +1537,10 @@ const char *c_strnstr(const char *s, const char *find, size_t slen); #define MG_ENABLE_STDIO CS_ENABLE_STDIO #endif +#ifndef MG_NET_IF +#define MG_NET_IF MG_NET_IF_SOCKET +#endif + #ifndef MG_ENABLE_THREADS /* ifdef-ok */ #ifdef _WIN32 #define MG_ENABLE_THREADS 1 @@ -1592,7 +1610,7 @@ const char *c_strnstr(const char *s, const char *find, size_t slen); #ifdef __APPLE__ #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif -#if !defined(MG_SOCKET_SIMPLELINK) +#if MG_NET_IF != MG_NET_IF_SIMPLELINK #include <openssl/ssl.h> #endif #endif /* MG_ENABLE_SSL */ @@ -1673,7 +1691,7 @@ struct mg_connection { struct mbuf recv_mbuf; /* Received data */ struct mbuf send_mbuf; /* Data scheduled for sending */ #if MG_ENABLE_SSL -#if !defined(MG_SOCKET_SIMPLELINK) +#if MG_NET_IF != MG_NET_IF_SIMPLELINK SSL *ssl; SSL_CTX *ssl_ctx; #else @@ -1950,7 +1968,7 @@ struct mg_connection *mg_connect_opt(struct mg_mgr *mgr, const char *address, mg_event_handler_t handler, struct mg_connect_opts opts); -#if MG_ENABLE_SSL && !defined(MG_SOCKET_SIMPLELINK) +#if MG_ENABLE_SSL && MG_NET_IF != MG_NET_IF_SIMPLELINK /* * Note: This function is deprecated. Please, use SSL options in * mg_connect_opt. @@ -2376,7 +2394,8 @@ void mg_set_close_on_exec(sock_t); */ void mg_conn_addr_to_str(struct mg_connection *nc, char *buf, size_t len, int flags); -#if !MG_DISABLE_SOCKET_IF /* Legacy interface. */ +#if MG_NET_IF == MG_NET_IF_SOCKET +/* Legacy interface. */ void mg_sock_to_str(sock_t sock, char *buf, size_t len, int flags); #endif