esp32: multi ap slots plus PEM certs and parallel build fixes
[platform/upstream/libwebsockets.git] / lib / private-libwebsockets.h
index e55c7f8..e2cee95 100644 (file)
@@ -208,6 +208,9 @@ int kill(int pid, int sig);
 #ifdef LWS_USE_LIBUV
 #include <uv.h>
 #endif
+#ifdef LWS_USE_LIBEVENT
+#include <event2/event.h>
+#endif
 
 #ifndef LWS_NO_FORK
 #ifdef LWS_HAVE_SYS_PRCTL_H
@@ -262,6 +265,7 @@ lws_plat_get_peer_simple(struct lws *wsi, char *name, int namelen);
 #endif /* not USE_OLD_CYASSL */
 #else
 #include <openssl/ssl.h>
+#if !defined(LWS_WITH_ESP32)
 #include <openssl/evp.h>
 #include <openssl/err.h>
 #include <openssl/md5.h>
@@ -270,7 +274,7 @@ lws_plat_get_peer_simple(struct lws *wsi, char *name, int namelen);
 #include <openssl/ecdh.h>
 #endif
 #include <openssl/x509v3.h>
-
+#endif
 #if (OPENSSL_VERSION_NUMBER < 0x0009080afL)
 /* later openssl defines this to negate the presence of tlsext... but it was only
  * introduced at 0.9.8j.  Earlier versions don't know it exists so don't
@@ -366,11 +370,23 @@ extern "C" {
 #endif
 
 #if defined(__sun) && defined(__GNUC__)
+
+#include <arpa/nameser_compat.h>
+
+#if !defined (BYTE_ORDER)
 # define BYTE_ORDER __BYTE_ORDER__
+#endif
+
+#if !defined(LITTLE_ENDIAN)
 # define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
+#endif
+
+#if !defined(BIG_ENDIAN)
 # define BIG_ENDIAN __ORDER_BIG_ENDIAN__
 #endif
 
+#endif /* sun + GNUC */
+
 #if !defined(BYTE_ORDER)
 # define BYTE_ORDER __BYTE_ORDER
 #endif
@@ -575,7 +591,7 @@ enum {
 struct lws_protocols;
 struct lws;
 
-#if defined(LWS_USE_LIBEV) || defined(LWS_USE_LIBUV)
+#if defined(LWS_USE_LIBEV) || defined(LWS_USE_LIBUV) || defined(LWS_USE_LIBEVENT)
 
 struct lws_io_watcher {
 #ifdef LWS_USE_LIBEV
@@ -584,6 +600,9 @@ struct lws_io_watcher {
 #ifdef LWS_USE_LIBUV
        uv_poll_t uv_watcher;
 #endif
+#ifdef LWS_USE_LIBEVENT
+       struct event *event_watcher;
+#endif
        struct lws_context *context;
 };
 
@@ -594,6 +613,9 @@ struct lws_signal_watcher {
 #ifdef LWS_USE_LIBUV
        uv_signal_t uv_watcher;
 #endif
+#ifdef LWS_USE_LIBEVENT
+       struct event *event_watcher;
+#endif
        struct lws_context *context;
 };
 #endif
@@ -670,7 +692,7 @@ struct lws_context_per_thread {
        struct lws *rx_draining_ext_list;
        struct lws *tx_draining_ext_list;
        struct lws *timeout_list;
-#ifdef LWS_USE_LIBUV
+#if defined(LWS_USE_LIBUV) || defined(LWS_USE_LIBEVENT)
        struct lws_context *context;
 #endif
 #ifdef LWS_WITH_CGI
@@ -692,10 +714,13 @@ struct lws_context_per_thread {
        uv_timer_t uv_timeout_watcher;
        uv_idle_t uv_idle;
 #endif
+#if defined(LWS_USE_LIBEVENT)
+       struct event_base *io_loop_event_base;
+#endif
 #if defined(LWS_USE_LIBEV)
        struct lws_io_watcher w_accept;
 #endif
-#if defined(LWS_USE_LIBEV) || defined(LWS_USE_LIBUV)
+#if defined(LWS_USE_LIBEV) || defined(LWS_USE_LIBUV) || defined(LWS_USE_LIBEVENT)
        struct lws_signal_watcher w_sigint;
        unsigned char ev_loop_foreign:1;
 #endif
@@ -795,6 +820,7 @@ struct lws_vhost {
        unsigned int created_vhost_protocols:1;
 
        unsigned char default_protocol_index;
+       unsigned char raw_protocol_index;
 };
 
 /*
@@ -809,7 +835,10 @@ struct lws_context {
        time_t last_ws_ping_pong_check_s;
        time_t time_up;
        const struct lws_plat_file_ops *fops;
-       struct lws_plat_file_ops fops_default[2];
+       struct lws_plat_file_ops fops_platform;
+#if defined(LWS_WITH_ZIP_FOPS)
+       struct lws_plat_file_ops fops_zip;
+#endif
        struct lws_context_per_thread pt[LWS_MAX_SMP];
        struct lws_conn_stats conn_stats;
 #ifdef _WIN32
@@ -841,14 +870,23 @@ struct lws_context {
 #if defined(LWS_USE_LIBUV)
        uv_signal_cb lws_uv_sigint_cb;
 #endif
+#if defined(LWS_USE_LIBEVENT)
+       lws_event_signal_cb_t * lws_event_sigint_cb;
+#endif
        char canonical_hostname[128];
 #ifdef LWS_LATENCY
        unsigned long worst_latency;
        char worst_latency_info[256];
 #endif
 
+#if defined(LWS_WITH_STATS)
+       uint64_t lws_stats[LWSSTATS_SIZE];
+       uint64_t last_dump;
+       int updated;
+#endif
+
        int max_fds;
-#if defined(LWS_USE_LIBEV) || defined(LWS_USE_LIBUV)
+#if defined(LWS_USE_LIBEV) || defined(LWS_USE_LIBUV) || defined(LWS_USE_LIBEVENT)
        int use_ev_sigint;
 #endif
        int started_with_parent;
@@ -873,6 +911,8 @@ struct lws_context {
        unsigned int timeout_secs;
        unsigned int pt_serv_buf_size;
        int max_http_header_data;
+       int simultaneous_ssl_restriction;
+       int simultaneous_ssl;
 
        unsigned int deprecated:1;
        unsigned int being_destroyed:1;
@@ -896,6 +936,7 @@ struct lws_context {
        short server_string_len;
        unsigned short ws_ping_pong_interval;
        unsigned short deprecation_pending_listen_close_count;
+       uint8_t max_fi;
 };
 
 #define lws_get_context_protocol(ctx, x) ctx->vhost_list->protocols[x]
@@ -931,6 +972,7 @@ enum {
 #if defined(LWS_USE_LIBEV)
 LWS_EXTERN void
 lws_libev_accept(struct lws *new_wsi, lws_sock_file_fd_type desc);
+LWS_EXTERN void
 lws_libev_io(struct lws *wsi, int flags);
 LWS_EXTERN int
 lws_libev_init_fd_table(struct lws_context *context);
@@ -985,6 +1027,34 @@ LWS_EXTERN void lws_feature_status_libuv(struct lws_context_creation_info *info)
 #endif
 #endif
 
+#if defined(LWS_USE_LIBEVENT)
+LWS_EXTERN void
+lws_libevent_accept(struct lws *new_wsi, lws_sock_file_fd_type desc);
+LWS_EXTERN void
+lws_libevent_io(struct lws *wsi, int flags);
+LWS_EXTERN int
+lws_libevent_init_fd_table(struct lws_context *context);
+LWS_EXTERN void
+lws_libevent_destroyloop(struct lws_context *context, int tsi);
+LWS_EXTERN void
+lws_libevent_run(const struct lws_context *context, int tsi);
+#define LWS_LIBEVENT_ENABLED(context) lws_check_opt(context->options, LWS_SERVER_OPTION_LIBEVENT)
+LWS_EXTERN void lws_feature_status_libevent(struct lws_context_creation_info *info);
+#else
+#define lws_libevent_accept(_a, _b) ((void) 0)
+#define lws_libevent_io(_a, _b) ((void) 0)
+#define lws_libevent_init_fd_table(_a) (0)
+#define lws_libevent_run(_a, _b) ((void) 0)
+#define lws_libevent_destroyloop(_a, _b) ((void) 0)
+#define LWS_LIBEVENT_ENABLED(context) (0)
+#if LWS_POSIX && !defined(LWS_WITH_ESP32)
+#define lws_feature_status_libevent(_a) \
+                       lwsl_notice("libevent support not compiled in\n")
+#else
+#define lws_feature_status_libevent(_a)
+#endif
+#endif
+
 
 #ifdef LWS_USE_IPV6
 #define LWS_IPV6_ENABLED(vh) \
@@ -1357,10 +1427,10 @@ struct lws {
 
        /* lifetime members */
 
-#if defined(LWS_USE_LIBEV) || defined(LWS_USE_LIBUV)
+#if defined(LWS_USE_LIBEV) || defined(LWS_USE_LIBUV) || defined(LWS_USE_LIBEVENT)
        struct lws_io_watcher w_read;
 #endif
-#if defined(LWS_USE_LIBEV)
+#if defined(LWS_USE_LIBEV) || defined(LWS_USE_LIBEVENT)
        struct lws_io_watcher w_write;
 #endif
        time_t pending_timeout_limit;
@@ -1401,6 +1471,9 @@ struct lws {
        SSL *ssl;
        BIO *client_bio;
        struct lws *pending_read_list_prev, *pending_read_list_next;
+#if defined(LWS_WITH_STATS)
+       uint64_t accept_start_us;
+#endif
 #endif
 #ifdef LWS_WITH_HTTP_PROXY
        struct lws_rewrite *rw;
@@ -1410,7 +1483,9 @@ struct lws {
        unsigned long latency_start;
 #endif
        lws_sock_file_fd_type desc; /* .filefd / .sockfd */
-
+#if defined(LWS_WITH_STATS)
+       uint64_t active_writable_req_us;
+#endif
        /* ints */
        int position_in_fds_table;
        int rxflow_len;
@@ -1438,7 +1513,7 @@ struct lws {
        unsigned int sending_chunked:1;
        unsigned int already_did_cce:1;
        unsigned int told_user_closed:1;
-       unsigned int :1;
+
 #if defined(LWS_WITH_ESP8266)
        unsigned int pending_send_completion:3;
        unsigned int close_is_pending_send_completion:1;
@@ -1468,6 +1543,10 @@ struct lws {
        unsigned int redirect_to_https:1;
 #endif
 
+       /* volatile to make sure code is aware other thread can change */
+       volatile unsigned int handling_pollout:1;
+       volatile unsigned int leave_pollout_active:1;
+
 #ifndef LWS_NO_CLIENT
        unsigned short c_port;
 #endif
@@ -1798,7 +1877,6 @@ lws_context_init_server_ssl(struct lws_context_creation_info *info,
 #endif
 LWS_EXTERN void
 lws_ssl_destroy(struct lws_vhost *vhost);
-
 /* HTTP2-related */
 
 #ifdef LWS_USE_HTTP2
@@ -1953,6 +2031,10 @@ void lws_free(void *p);
 #define lws_free_set_NULL(P)   do { lws_realloc(P, 0); (P) = NULL; } while(0)
 #endif
 
+const struct lws_plat_file_ops *
+lws_vfs_select_fops(const struct lws_plat_file_ops *fops, const char *vfs_path,
+                   const char **vpath);
+
 /* lws_plat_ */
 LWS_EXTERN void
 lws_plat_delete_socket_from_fds(struct lws_context *context,
@@ -1966,6 +2048,10 @@ lws_plat_service_periodic(struct lws_context *context);
 LWS_EXTERN int
 lws_plat_change_pollfd(struct lws_context *context, struct lws *wsi,
                       struct lws_pollfd *pfd);
+LWS_EXTERN void
+lws_add_wsi_to_draining_ext_list(struct lws *wsi);
+LWS_EXTERN void
+lws_remove_wsi_from_draining_ext_list(struct lws *wsi);
 LWS_EXTERN int
 lws_plat_context_early_init(void);
 LWS_EXTERN void
@@ -1990,6 +2076,31 @@ lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt);
 
 LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_check_utf8(unsigned char *state, unsigned char *buf, size_t len);
+LWS_EXTERN int alloc_file(struct lws_context *context, const char *filename, uint8_t **buf,
+                               lws_filepos_t *amount);
+LWS_EXTERN int alloc_pem_to_der_file(struct lws_context *context, const char *filename, uint8_t **buf,
+              lws_filepos_t *amount);
+
+LWS_EXTERN void
+lws_same_vh_protocol_remove(struct lws *wsi);
+LWS_EXTERN void
+lws_same_vh_protocol_insert(struct lws *wsi, int n);
+
+#if defined(LWS_WITH_STATS)
+void
+lws_stats_atomic_bump(struct lws_context * context,
+               struct lws_context_per_thread *pt, int index, uint64_t bump);
+void
+lws_stats_atomic_max(struct lws_context * context,
+               struct lws_context_per_thread *pt, int index, uint64_t val);
+#else
+static inline uint64_t lws_stats_atomic_bump(struct lws_context * context,
+               struct lws_context_per_thread *pt, int index, uint64_t bump) {
+       (void)context; (void)pt; (void)index; (void)bump; return 0; }
+static inline uint64_t lws_stats_atomic_max(struct lws_context * context,
+               struct lws_context_per_thread *pt, int index, uint64_t val) {
+       (void)context; (void)pt; (void)index; (void)val; return 0; }
+#endif
 
 #ifdef __cplusplus
 };