diff --git a/.gitignore b/.gitignore index 74c0e3c7cb4df06862f33ac10918252c035c8a44..eea4395c2e48e046c52e15fc25d1102191585116 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ build/ doc /build2/ /build3/ +/cov-int/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 93d7210d148d1c2aebff8df18354952678b123f1..c59bc990d67600c7cfd59593a3c9a5f9bebe1a04 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -718,7 +718,7 @@ include_directories("${PROJECT_SOURCE_DIR}/lib") # Group headers and sources. # Some IDEs use this for nicer file structure. set(HDR_PRIVATE - lib/private-libwebsockets.h) + lib/core/private.h) set(HDR_PUBLIC "${PROJECT_SOURCE_DIR}/lib/libwebsockets.h" @@ -728,12 +728,12 @@ set(HDR_PUBLIC set(SOURCES lib/misc/base64-decode.c - lib/libwebsockets.c - lib/service.c - lib/pollfd.c - lib/output.c - lib/context.c - lib/alloc.c + lib/core/libwebsockets.c + lib/core/service.c + lib/core/pollfd.c + lib/core/output.c + lib/core/context.c + lib/core/alloc.c lib/roles/pipe/ops-pipe.c lib/misc/lws-ring.c) @@ -1645,29 +1645,6 @@ if ((LWS_ROLE_H1 OR LWS_ROLE_H2) AND NOT LWS_WITHOUT_TESTAPPS) "" "") endif() - if (NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) - AND LWS_WITH_LIBEV) - create_test_app(test-server-libev - "test-apps/test-server-libev.c" - "" - "" - "" - "" - "") - # libev generates a big mess of warnings with gcc, maintainer claims gcc to blame - set_source_files_properties( test-apps/test-server-libev.c PROPERTIES COMPILE_FLAGS "-Wno-error" ) - - endif() - if (NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) - AND LWS_WITH_LIBEVENT) - create_test_app(test-server-libevent - "test-apps/test-server-libevent.c" - "" - "" - "" - "" - "") - endif() endif() # diff --git a/lib/README.md b/lib/README.md new file mode 100644 index 0000000000000000000000000000000000000000..d6475b8da5fad5b14ec562d593852ab198210d1a --- /dev/null +++ b/lib/README.md @@ -0,0 +1,14 @@ +## Library sources layout + +Code that goes in the libwebsockets library itself lives down ./lib + +Path|Sources +---|--- +lib/core|Core lws code related to generic fd and wsi servicing and management +lib/event-libs|Code containing optional event-lib specific adaptations +lib/misc|Code for various mostly optional miscellaneous features +lib/plat|Platform-specific adaptation code +lib/roles|Code for specific optional wsi roles, eg, http/1, h2, ws, raw, etc +lib/tls|Code supporting the various TLS libraries +libwebsockets.h|Public API header for the whole of lws + diff --git a/lib/alloc.c b/lib/core/alloc.c similarity index 98% rename from lib/alloc.c rename to lib/core/alloc.c index e8a376675ba173b736d721cd1d4ee19576d877e2..f169fc376797cdf3e9df21414b69b435bf769b3c 100644 --- a/lib/alloc.c +++ b/lib/core/alloc.c @@ -1,4 +1,4 @@ -#include "private-libwebsockets.h" +#include "core/private.h" #if defined(LWS_PLAT_OPTEE) diff --git a/lib/context.c b/lib/core/context.c similarity index 99% rename from lib/context.c rename to lib/core/context.c index 2ccfbe96efec7dec32b0b5b0be18910e94d113e3..db9151b95f2ba76cddf9944a074bc60ef58142b6 100644 --- a/lib/context.c +++ b/lib/core/context.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" #ifndef LWS_BUILD_HASH #define LWS_BUILD_HASH "unknown-build-hash" diff --git a/lib/libwebsockets.c b/lib/core/libwebsockets.c similarity index 99% rename from lib/libwebsockets.c rename to lib/core/libwebsockets.c index 28bb2fe0e68267d5e78995882a38e33e9959be74..343b63beacfa25969fd37ea9127ba4effe717b43 100644 --- a/lib/libwebsockets.c +++ b/lib/core/libwebsockets.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" #ifdef LWS_HAVE_SYS_TYPES_H #include <sys/types.h> @@ -672,8 +672,9 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason, const char * if (!wsi->told_user_closed && lwsi_role_http(wsi) && lwsi_role_server(wsi)) { - if (wsi->user_space && wsi->protocol_bind_balance) { - wsi->vhost->protocols->callback(wsi, + if (wsi->user_space && wsi->protocol && + wsi->protocol_bind_balance) { + wsi->protocol->callback(wsi, LWS_CALLBACK_HTTP_DROP_PROTOCOL, wsi->user_space, NULL, 0); wsi->protocol_bind_balance = 0; @@ -2927,7 +2928,7 @@ lws_cmdline_option(int argc, const char **argv, const char *val) while (--c > 0) if (!strncmp(argv[c], val, n)) { - if (!*(argv[c] + n) && c != argc - 1) + if (!*(argv[c] + n) && c < argc - 1) return argv[c + 1]; return argv[c] + n; diff --git a/lib/output.c b/lib/core/output.c similarity index 99% rename from lib/output.c rename to lib/core/output.c index 7d1a74869d27ed4591ff57b3a5e91fc34e0f1aa3..e2ff18ef275a1fa27737109a4a8b2146ea8873c0 100644 --- a/lib/output.c +++ b/lib/core/output.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" /* * notice this returns number of bytes consumed, or -1 diff --git a/lib/pollfd.c b/lib/core/pollfd.c similarity index 99% rename from lib/pollfd.c rename to lib/core/pollfd.c index 6a06d51f4139e440f7c0f9fa30da4edbb12efad5..fbc6132a752e843b948fa90b98d44d827f61c2d0 100644 --- a/lib/pollfd.c +++ b/lib/core/pollfd.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" int _lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa) diff --git a/lib/private-libwebsockets.h b/lib/core/private.h similarity index 99% rename from lib/private-libwebsockets.h rename to lib/core/private.h index 9f60bd6067c7deb1a20e357b2dcb53583b785c93..cb3ab4caed8c4d38f9ac94e6ef890ecda812c9b4 100644 --- a/lib/private-libwebsockets.h +++ b/lib/core/private.h @@ -26,8 +26,14 @@ #define _GNU_SOURCE #endif -#if defined(__COVERITY__) - typedef struct { long double x, y; } _Float128; +#if defined(__COVERITY__) && !defined(LWS_COVERITY_WORKAROUND) + #define LWS_COVERITY_WORKAROUND + typedef float _Float32; + typedef float _Float64; + typedef float _Float128; + typedef float _Float32x; + typedef float _Float64x; + typedef float _Float128x; #endif #ifdef LWS_HAVE_SYS_TYPES_H @@ -1076,8 +1082,8 @@ struct lws { #endif #endif - lws_usec_t pending_timer; - time_t pending_timeout_set; + lws_usec_t pending_timer; /* hrtimer fires */ + time_t pending_timeout_set; /* second-resolution timeout start */ /* ints */ int position_in_fds_table; @@ -1443,7 +1449,7 @@ lws_pt_unlock(struct lws_context_per_thread *pt) pt->lock_depth--; return; } - pt->last_lock_reason ="free"; + pt->last_lock_reason = "free"; pt->lock_owner = 0; //lwsl_notice("tid %d: unlock %s\n", pt->tid, pt->last_lock_reason); pthread_mutex_unlock(&pt->lock); diff --git a/lib/service.c b/lib/core/service.c similarity index 99% rename from lib/service.c rename to lib/core/service.c index a08506fbf9c2954379eeab9b1fc1c612b7530dcd..6523058814de992529002e92cbf60f8ed834ba51 100644 --- a/lib/service.c +++ b/lib/core/service.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" int lws_callback_as_writeable(struct lws *wsi) diff --git a/lib/event-libs/libev/libev.c b/lib/event-libs/libev/libev.c index d60072c0d43d756d7710a29d045bb5b73f4f1b37..3a9853d45301ac857d44d0b556adb3bc4d0938b2 100644 --- a/lib/event-libs/libev/libev.c +++ b/lib/event-libs/libev/libev.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" static void lws_ev_hrtimer_cb(struct ev_loop *loop, struct ev_timer *watcher, int revents) diff --git a/lib/event-libs/libev/private.h b/lib/event-libs/libev/private.h index 52de727a2eebb3ee28ba01772423311dde9c55e0..9359f34b3d1113d90de764a9296ccf60bc192861 100644 --- a/lib/event-libs/libev/private.h +++ b/lib/event-libs/libev/private.h @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA * - * This is included from private-libwebsockets.h if LWS_WITH_LIBEV + * This is included from core/private.h if LWS_WITH_LIBEV */ #include <ev.h> diff --git a/lib/event-libs/libevent/libevent.c b/lib/event-libs/libevent/libevent.c index 5cb47263a359cb70989016c2060efea34c6da004..f4f5cfd57a5a2494a1ce9114bb95da9fd7e84275 100644 --- a/lib/event-libs/libevent/libevent.c +++ b/lib/event-libs/libevent/libevent.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" static void lws_event_hrtimer_cb(int fd, short event, void *p) diff --git a/lib/event-libs/libevent/private.h b/lib/event-libs/libevent/private.h index 1c2d3607cb987d2f1a898b180ecfba83be0bef0c..04fbbdf6b620ffd07107f11e9aaddd1f7484dd68 100644 --- a/lib/event-libs/libevent/private.h +++ b/lib/event-libs/libevent/private.h @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA * - * This is included from private-libwebsockets.h if LWS_WITH_LIBEVENT + * This is included from core/private.h if LWS_WITH_LIBEVENT */ #include <event2/event.h> diff --git a/lib/event-libs/libuv/libuv.c b/lib/event-libs/libuv/libuv.c index ee948b64135c23b7628db3bbd34b59536485002b..b5c8b85f41f0a4409329c8b212885e6dd8fb82a3 100644 --- a/lib/event-libs/libuv/libuv.c +++ b/lib/event-libs/libuv/libuv.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" static void lws_uv_hrtimer_cb(uv_timer_t *timer @@ -666,21 +666,18 @@ static int elops_init_vhost_listen_wsi_uv(struct lws *wsi) { struct lws_context_per_thread *pt; - struct lws_vhost *vh = wsi->vhost; int n; - if (!wsi) - wsi = vh->lserv_wsi; if (!wsi) return 0; if (wsi->w_read.context) return 0; - pt = &vh->context->pt[(int)wsi->tsi]; + pt = &wsi->context->pt[(int)wsi->tsi]; if (!pt->uv.io_loop) return 0; - wsi->w_read.context = vh->context; + wsi->w_read.context = wsi->context; n = uv_poll_init_socket(pt->uv.io_loop, &wsi->w_read.uv.watcher, wsi->desc.sockfd); if (n) { diff --git a/lib/event-libs/libuv/private.h b/lib/event-libs/libuv/private.h index cf8f71045653207b4fbc9c96768d4fea8618f630..58a263915a5d3314d4a5cb632299bdbd97ddaca7 100644 --- a/lib/event-libs/libuv/private.h +++ b/lib/event-libs/libuv/private.h @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA * - * This is included from private-libwebsockets.h if LWS_WITH_LIBUV + * This is included from core/private.h if LWS_WITH_LIBUV */ #include <uv.h> diff --git a/lib/event-libs/poll/poll.c b/lib/event-libs/poll/poll.c index ad6b29b01f93cccc4398dde4f75a01fb2792ad27..09af5b15d83977ef7c6cb1c6b0236baef8e2fe4b 100644 --- a/lib/event-libs/poll/poll.c +++ b/lib/event-libs/poll/poll.c @@ -18,10 +18,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA * - * This is included from private-libwebsockets.h if LWS_ROLE_WS + * This is included from core/private.h if LWS_ROLE_WS */ -#include <private-libwebsockets.h> +#include <core/private.h> struct lws_event_loop_ops event_loop_ops_poll = { /* name */ "poll", diff --git a/lib/event-libs/private.h b/lib/event-libs/private.h index 59705c9ece28baeb2792c88c67e7e94e39c586cd..c36d39c8c2f94058b49e17cfe49a21a6864b35ce 100644 --- a/lib/event-libs/private.h +++ b/lib/event-libs/private.h @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA * - * This is included from private-libwebsockets.h + * This is included from core/private.h */ struct lws_event_loop_ops { diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 14c65ac0e9438fec6aa58c20eb4c7ee36698201c..c4f8bcbe305abff7c4c182e85c0bc847216aa251 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -27,7 +27,7 @@ #ifdef __cplusplus #include <cstddef> #include <cstdarg> -# + extern "C" { #else #include <stdarg.h> diff --git a/lib/misc/base64-decode.c b/lib/misc/base64-decode.c index 27db51f60a0036956893fe29724ad1e67eb45c12..64b84d78facbd78a53d5a987df6ce30eda334bc5 100644 --- a/lib/misc/base64-decode.c +++ b/lib/misc/base64-decode.c @@ -40,7 +40,7 @@ #include <stdio.h> #include <string.h> -#include "private-libwebsockets.h" +#include "core/private.h" static const char encode_orig[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz0123456789+/"; diff --git a/lib/misc/daemonize.c b/lib/misc/daemonize.c index eb92821cc9c9327042fd296a040680600f4c0861..457f2903b16027130283d451e7f68d45b813e6e7 100644 --- a/lib/misc/daemonize.c +++ b/lib/misc/daemonize.c @@ -22,7 +22,7 @@ #include <unistd.h> #include <errno.h> -#include "private-libwebsockets.h" +#include "core/private.h" int pid_daemon; static char *lock_path; diff --git a/lib/misc/getifaddrs.c b/lib/misc/getifaddrs.c index 4f42ab45954601dc44766f954085b49fa173e054..735b899f48dc3501dc5b6b461ec47c777cccb47d 100644 --- a/lib/misc/getifaddrs.c +++ b/lib/misc/getifaddrs.c @@ -43,7 +43,7 @@ #include <string.h> #include <sys/ioctl.h> #include <unistd.h> -#include "private-libwebsockets.h" +#include "core/private.h" #ifdef LWS_HAVE_SYS_SOCKIO_H #include <sys/sockio.h> diff --git a/lib/misc/jws/jwk.c b/lib/misc/jws/jwk.c index 000da84fae6c12d6594ddb870d1bfa25349adad8..2337d5e8cfe0c54017db5f3f5ae612075b2624af 100644 --- a/lib/misc/jws/jwk.c +++ b/lib/misc/jws/jwk.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" #include <fcntl.h> #include <unistd.h> diff --git a/lib/misc/jws/jws.c b/lib/misc/jws/jws.c index feacfe0ca0a552ce03e264d6be53e3aea1606348..23a863ca5268d26e59333930207c4106e0f60b59 100644 --- a/lib/misc/jws/jws.c +++ b/lib/misc/jws/jws.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" /* * JSON Web Signature is defined in RFC7515 diff --git a/lib/misc/lws-ring.c b/lib/misc/lws-ring.c index d1079cae0fa715375b69f45d0963f5981000aaf1..bbd4df96da782af96f591680828ca02ea39321be 100644 --- a/lib/misc/lws-ring.c +++ b/lib/misc/lws-ring.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" LWS_VISIBLE LWS_EXTERN struct lws_ring * lws_ring_create(size_t element_len, size_t count, diff --git a/lib/misc/peer-limits.c b/lib/misc/peer-limits.c index 373ec54c46152313c3e409cfa3ac390100170a8b..66deef49d0cbcfc9915e92d656e7203d7b6fb7f3 100644 --- a/lib/misc/peer-limits.c +++ b/lib/misc/peer-limits.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" /* requires context->lock */ static void diff --git a/lib/misc/sha-1.c b/lib/misc/sha-1.c index 50205a0100b3174ebaf3bc9bb114352b6001d01d..2e4db52693fab8fce93f040035d646ce8ac09c0b 100644 --- a/lib/misc/sha-1.c +++ b/lib/misc/sha-1.c @@ -32,7 +32,7 @@ * implemented by Jun-ichiro itojun Itoh <itojun@itojun.org> */ -#include "private-libwebsockets.h" +#include "core/private.h" #ifdef LWS_HAVE_SYS_TYPES_H #include <sys/types.h> diff --git a/lib/misc/smtp.c b/lib/misc/smtp.c index dc76360c6c18c85557e42c19627a6495dbadfaa0..290499c159fcd17ab5d0aef83416d603c3252ebd 100644 --- a/lib/misc/smtp.c +++ b/lib/misc/smtp.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" static unsigned int lwsgs_now_secs(void) diff --git a/lib/plat/lws-plat-esp32.c b/lib/plat/lws-plat-esp32.c index 89f1fb6b0a9c8710c28611cab5c11997cff0b034..ff53e13339deda861abc31df5667608c4fbc0d2f 100644 --- a/lib/plat/lws-plat-esp32.c +++ b/lib/plat/lws-plat-esp32.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" #include "freertos/timers.h" #include <esp_attr.h> #include <esp_system.h> diff --git a/lib/plat/lws-plat-optee.c b/lib/plat/lws-plat-optee.c index ab04f842edb760fc59ff9039be47f75824c9825b..ec649cd1e145672c4494ed9e30ba83f5a60a5c0e 100644 --- a/lib/plat/lws-plat-optee.c +++ b/lib/plat/lws-plat-optee.c @@ -1,4 +1,4 @@ -#include "private-libwebsockets.h" +#include "core/private.h" /* * included from libwebsockets.c for OPTEE builds diff --git a/lib/plat/lws-plat-unix.c b/lib/plat/lws-plat-unix.c index 2c103bb1e0510498754f255f261533ee7ae9026b..5b59f20aab30aca8de7e037775a5bd61fb1179da 100644 --- a/lib/plat/lws-plat-unix.c +++ b/lib/plat/lws-plat-unix.c @@ -20,7 +20,7 @@ */ #define _GNU_SOURCE -#include "private-libwebsockets.h" +#include "core/private.h" #include <pwd.h> #include <grp.h> diff --git a/lib/plat/lws-plat-win.c b/lib/plat/lws-plat-win.c index 287e144ce1185babd0ffd8781aae4037293a74c8..b7f28de65159a5b8f7a6727baf9b7ada3609089d 100644 --- a/lib/plat/lws-plat-win.c +++ b/lib/plat/lws-plat-win.c @@ -1,7 +1,7 @@ #ifndef _WINSOCK_DEPRECATED_NO_WARNINGS #define _WINSOCK_DEPRECATED_NO_WARNINGS #endif -#include "private-libwebsockets.h" +#include "core/private.h" int lws_plat_socket_offset(void) diff --git a/lib/roles/cgi/cgi-server.c b/lib/roles/cgi/cgi-server.c index 4fc8305b45c5036b14922ac49ad7c92b86b8a5cd..e5a466a7c84549c9cc9068d6feaac0afd85e76ab 100644 --- a/lib/roles/cgi/cgi-server.c +++ b/lib/roles/cgi/cgi-server.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" #if defined(WIN32) || defined(_WIN32) #else diff --git a/lib/roles/cgi/ops-cgi.c b/lib/roles/cgi/ops-cgi.c index bc42c10ee8833d4e1ed477ef35c25599afe3ca6e..8555f7baa5180b8b525b48a2c87cbdc3da87876a 100644 --- a/lib/roles/cgi/ops-cgi.c +++ b/lib/roles/cgi/ops-cgi.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include <private-libwebsockets.h> +#include <core/private.h> static int rops_handle_POLLIN_cgi(struct lws_context_per_thread *pt, struct lws *wsi, diff --git a/lib/roles/cgi/private.h b/lib/roles/cgi/private.h index 868dba03fe2ab3dcf813e14524a9caaa817c1c1a..b964ce03f3b6d2adafc9d9080aadc46e9d5fa762 100644 --- a/lib/roles/cgi/private.h +++ b/lib/roles/cgi/private.h @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA * - * This is included from private-libwebsockets.h if LWS_ROLE_WS + * This is included from core/private.h if LWS_ROLE_WS */ extern struct lws_role_ops role_ops_cgi; diff --git a/lib/roles/h1/ops-h1.c b/lib/roles/h1/ops-h1.c index 172b8d82321ca91edb2722e7ca42122846349bc7..8afd62680834864e8e379936b592d6f2f77c62ad 100644 --- a/lib/roles/h1/ops-h1.c +++ b/lib/roles/h1/ops-h1.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include <private-libwebsockets.h> +#include <core/private.h> #ifndef min #define min(a, b) ((a) < (b) ? (a) : (b)) diff --git a/lib/roles/h1/private.h b/lib/roles/h1/private.h index 17e7a90e0d9978c446ac371cb18dbd4443153437..3f53954d337dd5004a39ef3cbf9c8943818c9d75 100644 --- a/lib/roles/h1/private.h +++ b/lib/roles/h1/private.h @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA * - * This is included from private-libwebsockets.h if LWS_ROLE_H1 + * This is included from core/private.h if LWS_ROLE_H1 * * Most of the h1 business is defined in the h1 / h2 common roles/http dir */ diff --git a/lib/roles/h2/hpack.c b/lib/roles/h2/hpack.c index 6e802764aff05cad1330d14434eed2d3bf6b4c81..d25849d0a1d9534ea83d2b0b0558af4c1d3dbc3e 100644 --- a/lib/roles/h2/hpack.c +++ b/lib/roles/h2/hpack.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" /* * Official static header table for HPACK diff --git a/lib/roles/h2/http2.c b/lib/roles/h2/http2.c index c61eb841361c5782fb8d6df0a85d160022ae11d9..d630872fbdb254d3a2008b2d2056be1766255542 100644 --- a/lib/roles/h2/http2.c +++ b/lib/roles/h2/http2.c @@ -20,7 +20,7 @@ */ -#include "private-libwebsockets.h" +#include "core/private.h" /* * bitmap of control messages that are valid to receive for each http2 state diff --git a/lib/roles/h2/ops-h2.c b/lib/roles/h2/ops-h2.c index abd7e125abaf73aaf4d91969e67587fdf3992f59..0e0afeeacc19fba6614c84bec2553bec80bb1153 100644 --- a/lib/roles/h2/ops-h2.c +++ b/lib/roles/h2/ops-h2.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include <private-libwebsockets.h> +#include <core/private.h> /* * These are the standardized defaults. diff --git a/lib/roles/h2/private.h b/lib/roles/h2/private.h index 0341b4ad4ab236a4c6ad80b81b5672cee11b0a1a..664c509dc90f88816f15036d4ab82be1858c045b 100644 --- a/lib/roles/h2/private.h +++ b/lib/roles/h2/private.h @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA * - * This is included from private-libwebsockets.h if LWS_ROLE_H2 + * This is included from core/private.h if LWS_ROLE_H2 */ extern struct lws_role_ops role_ops_h2; diff --git a/lib/roles/http/client/client-handshake.c b/lib/roles/http/client/client-handshake.c index a28d7fe18e97170033261bfe430ae68a8ae087c6..337ccea986cc9833825b305f23ce82bdd5b74ce0 100644 --- a/lib/roles/http/client/client-handshake.c +++ b/lib/roles/http/client/client-handshake.c @@ -1,4 +1,4 @@ -#include "private-libwebsockets.h" +#include "core/private.h" static int lws_getaddrinfo46(struct lws *wsi, const char *ads, struct addrinfo **result) @@ -78,7 +78,9 @@ lws_client_connect_2(struct lws *wsi) */ adsin = lws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS); - lws_vhost_lock(wsi->vhost); + + lws_vhost_lock(wsi->vhost); /* ----------------------------------- { */ + lws_start_foreach_dll_safe(struct lws_dll_lws *, d, d1, wsi->vhost->dll_active_client_conns.next) { struct lws *w = lws_container_of(d, struct lws, @@ -101,6 +103,7 @@ lws_client_connect_2(struct lws *wsi) if (w->keepalive_rejected) { lwsl_info("defeating pipelining due to no " "keepalive on server\n"); + lws_vhost_unlock(wsi->vhost); /* } ---------- */ goto create_new_conn; } #if defined (LWS_WITH_HTTP2) @@ -117,7 +120,7 @@ lws_client_connect_2(struct lws *wsi) wsi->client_h2_alpn = 1; lws_wsi_h2_adopt(w, wsi); - lws_vhost_unlock(wsi->vhost); + lws_vhost_unlock(wsi->vhost); /* } ---------- */ return wsi; } @@ -140,12 +143,13 @@ lws_client_connect_2(struct lws *wsi) wsi_piggyback = w; - lws_vhost_unlock(wsi->vhost); + lws_vhost_unlock(wsi->vhost); /* } ---------- */ goto send_hs; } } lws_end_foreach_dll_safe(d, d1); - lws_vhost_unlock(wsi->vhost); + + lws_vhost_unlock(wsi->vhost); /* } ---------------------------------- */ create_new_conn: #endif diff --git a/lib/roles/http/client/client.c b/lib/roles/http/client/client.c index e035dbac0fc7dd578ae4d877857f420417ac8556..ce42dc6cd3a0cae6a5bb66673745816524120c20 100644 --- a/lib/roles/http/client/client.c +++ b/lib/roles/http/client/client.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" LWS_VISIBLE LWS_EXTERN void lws_client_http_body_pending(struct lws *wsi, int something_left_to_send) diff --git a/lib/roles/http/header.c b/lib/roles/http/header.c index eef5fde075d429fcbe1f5d30c6772e23806bec83..99e56f75641fe9d64296938bc4c1ec8c6810177c 100644 --- a/lib/roles/http/header.c +++ b/lib/roles/http/header.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" #include "lextable-strings.h" diff --git a/lib/roles/http/private.h b/lib/roles/http/private.h index 2411ec89ddec93460bb3c2d67f0b385169e4dfe6..2aa7a92f7516484f0564a8af0a2ca4e4ed6cf119 100644 --- a/lib/roles/http/private.h +++ b/lib/roles/http/private.h @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA * - * This is included from private-libwebsockets.h if either H1 or H2 roles are + * This is included from core/private.h if either H1 or H2 roles are * enabled */ diff --git a/lib/roles/http/server/access-log.c b/lib/roles/http/server/access-log.c index c07e557047e67428b5b6bb29f17fca49caada72f..0e75309d7ae154442b6555d277e90d2506a065e2 100644 --- a/lib/roles/http/server/access-log.c +++ b/lib/roles/http/server/access-log.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" /* * Produce Apache-compatible log string for wsi, like this: diff --git a/lib/roles/http/server/fops-zip.c b/lib/roles/http/server/fops-zip.c index f8ede1f25fa93e300699f21862a5355242a784aa..4db83ce6211eb228cf6f451955d0f5ae851402d2 100644 --- a/lib/roles/http/server/fops-zip.c +++ b/lib/roles/http/server/fops-zip.c @@ -51,7 +51,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" #include <zlib.h> diff --git a/lib/roles/http/server/lejp-conf.c b/lib/roles/http/server/lejp-conf.c index b41779d2b31638353cdd330e43f041b179cdbbd8..e9ce854cfc74352bab9a28acd54fc3b22eb4d020 100644 --- a/lib/roles/http/server/lejp-conf.c +++ b/lib/roles/http/server/lejp-conf.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" #ifndef _WIN32 /* this is needed for Travis CI */ diff --git a/lib/roles/http/server/lws-spa.c b/lib/roles/http/server/lws-spa.c index b3ed050c3b73775a9a98b7dcf79fb9ed920eb9fc..88675ef9a0b50d64c500fd91bae57f5b2a2463b5 100644 --- a/lib/roles/http/server/lws-spa.c +++ b/lib/roles/http/server/lws-spa.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" #define LWS_MAX_ELEM_NAME 32 diff --git a/lib/roles/http/server/parsers.c b/lib/roles/http/server/parsers.c index 21d44dba65d34510d7971c59d914cab19a016def..5754f9099c49f1891f31f839469b177a00f35e81 100644 --- a/lib/roles/http/server/parsers.c +++ b/lib/roles/http/server/parsers.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" static const unsigned char lextable[] = { #include "../lextable.h" diff --git a/lib/roles/http/server/ranges.c b/lib/roles/http/server/ranges.c index bc1578d733b1892974da6b1cbdcaf3650950830f..f69c33cba3986dfb471c088775181cddc5012a51 100644 --- a/lib/roles/http/server/ranges.c +++ b/lib/roles/http/server/ranges.c @@ -21,7 +21,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" /* * RFC7233 examples diff --git a/lib/roles/http/server/rewrite.c b/lib/roles/http/server/rewrite.c index 2f9b0c491f7f0328d66bc9fc823e0d73cc49e8c2..61bb613d902341055cea8ce1601c70efcf27c834 100644 --- a/lib/roles/http/server/rewrite.c +++ b/lib/roles/http/server/rewrite.c @@ -1,4 +1,4 @@ -#include "private-libwebsockets.h" +#include "core/private.h" LWS_EXTERN struct lws_rewrite * diff --git a/lib/roles/http/server/server.c b/lib/roles/http/server/server.c index 83f5de8a1f555011b6c5a117b03eb7b6068efddc..a308683f10aca06cc635e74728c6089c62859cfc 100644 --- a/lib/roles/http/server/server.c +++ b/lib/roles/http/server/server.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" const char * const method_names[] = { "GET", "POST", "OPTIONS", "PUT", "PATCH", "DELETE", "CONNECT", "HEAD", diff --git a/lib/roles/listen/ops-listen.c b/lib/roles/listen/ops-listen.c index 02f028a8c74d7d4e7babfb5538b7ad06a217c88f..0e463231c672a652c796bb957b7dee846b82b351 100644 --- a/lib/roles/listen/ops-listen.c +++ b/lib/roles/listen/ops-listen.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include <private-libwebsockets.h> +#include <core/private.h> static int rops_handle_POLLIN_listen(struct lws_context_per_thread *pt, struct lws *wsi, diff --git a/lib/roles/pipe/ops-pipe.c b/lib/roles/pipe/ops-pipe.c index 4fd4902715a98d9c29465c4836f2dab538343297..b9348d58d7238a41e3962ec08f0a566962d1e87b 100644 --- a/lib/roles/pipe/ops-pipe.c +++ b/lib/roles/pipe/ops-pipe.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include <private-libwebsockets.h> +#include <core/private.h> static int rops_handle_POLLIN_pipe(struct lws_context_per_thread *pt, struct lws *wsi, diff --git a/lib/roles/private.h b/lib/roles/private.h index f13e14aeb36bfe6f50841ca7e43678e5ab73139d..4e0b3126111f09b80e6d9abcd6f712bde1d97be7 100644 --- a/lib/roles/private.h +++ b/lib/roles/private.h @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA * - * This is included from private-libwebsockets.h + * This is included from core/private.h */ typedef uint32_t lws_wsi_state_t; diff --git a/lib/roles/raw/ops-raw.c b/lib/roles/raw/ops-raw.c index e94af046983892013f6f7640392acd6aa202fd0b..68b52bded64bbb026ed8995c669b881bcaac87e1 100644 --- a/lib/roles/raw/ops-raw.c +++ b/lib/roles/raw/ops-raw.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include <private-libwebsockets.h> +#include <core/private.h> static int rops_handle_POLLIN_raw_skt(struct lws_context_per_thread *pt, struct lws *wsi, diff --git a/lib/roles/ws/client-parser-ws.c b/lib/roles/ws/client-parser-ws.c index 8e74a6ddfe3fec6a619559692e54d55a775dd790..aa561ce034c961524af46dc323bdf68e6b4d36f2 100644 --- a/lib/roles/ws/client-parser-ws.c +++ b/lib/roles/ws/client-parser-ws.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" /* * parsers.c: lws_ws_rx_sm() needs to be roughly kept in @@ -29,10 +29,13 @@ int lws_ws_client_rx_sm(struct lws *wsi, unsigned char c) { int callback_action = LWS_CALLBACK_CLIENT_RECEIVE; - int handled, n, m, rx_draining_ext = 0; + int handled, m; unsigned short close_code; struct lws_tokens ebuf; unsigned char *pp; +#if !defined(LWS_WITHOUT_EXTENSIONS) + int rx_draining_ext = 0, n; +#endif ebuf.token = NULL; ebuf.len = 0; @@ -498,12 +501,14 @@ drain_extension: wsi->socket_is_permanently_unusable = 1; return -1; } -#else - n = 0; #endif lwsl_debug("post inflate ebuf len %d\n", ebuf.len); - if (rx_draining_ext && !ebuf.len) { + if ( +#if !defined(LWS_WITHOUT_EXTENSIONS) + rx_draining_ext && +#endif + !ebuf.len) { lwsl_debug(" --- ending drain on 0 read result\n"); goto already_done; } @@ -520,7 +525,11 @@ drain_extension: /* we are ending partway through utf-8 character? */ if (!wsi->ws->rx_packet_length && wsi->ws->final && - wsi->ws->utf8 && !n) { + wsi->ws->utf8 +#if !defined(LWS_WITHOUT_EXTENSIONS) + && !n +#endif + ) { lwsl_info("FINAL utf8 error\n"); lws_close_reason(wsi, LWS_CLOSE_STATUS_INVALID_PAYLOAD, @@ -550,9 +559,9 @@ utf8_fail: if ( /* coverity says dead code otherwise */ -//#if !defined(LWS_WITHOUT_EXTENSIONS) +#if !defined(LWS_WITHOUT_EXTENSIONS) n && -//#endif +#endif ebuf.len) /* extension had more... main loop will come back * we want callback to be done with this set, if so, diff --git a/lib/roles/ws/client-ws.c b/lib/roles/ws/client-ws.c index 10b69f01996247c7f50fa5b1759dc35ef46c77a6..fd6cf4255129c24e9d20617349b983121332ae07 100644 --- a/lib/roles/ws/client-ws.c +++ b/lib/roles/ws/client-ws.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include <private-libwebsockets.h> +#include <core/private.h> /* * In-place str to lower case diff --git a/lib/roles/ws/ext/extension-permessage-deflate.c b/lib/roles/ws/ext/extension-permessage-deflate.c index e23d80d251dce816e8a954c2e373b3bbfc1a1b3a..728aa5c74caec6973a4e5bd05e978d6b134ac140 100644 --- a/lib/roles/ws/ext/extension-permessage-deflate.c +++ b/lib/roles/ws/ext/extension-permessage-deflate.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" #include "extension-permessage-deflate.h" #include <stdio.h> #include <string.h> diff --git a/lib/roles/ws/ext/extension.c b/lib/roles/ws/ext/extension.c index d20c9568b7c04d41e1474481759a69f4ebab7c04..a45f3bac3e1b618a71296b1902ef93c58557fcda 100644 --- a/lib/roles/ws/ext/extension.c +++ b/lib/roles/ws/ext/extension.c @@ -1,4 +1,4 @@ -#include "private-libwebsockets.h" +#include "core/private.h" #include "extension-permessage-deflate.h" diff --git a/lib/roles/ws/ops-ws.c b/lib/roles/ws/ops-ws.c index 9e2a52f0c670faa921ef4832a47093f2617bfe23..fd036c314ed7a338a6cc9bbf47d394676591ef6d 100644 --- a/lib/roles/ws/ops-ws.c +++ b/lib/roles/ws/ops-ws.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include <private-libwebsockets.h> +#include <core/private.h> #define LWS_CPYAPP(ptr, str) { strcpy(ptr, str); ptr += strlen(str); } @@ -32,12 +32,13 @@ int lws_ws_rx_sm(struct lws *wsi, char already_processed, unsigned char c) { int callback_action = LWS_CALLBACK_RECEIVE; - int ret = 0, rx_draining_ext = 0; + int ret = 0; unsigned short close_code; struct lws_tokens ebuf; unsigned char *pp; int n = 0; #if !defined(LWS_WITHOUT_EXTENSIONS) + int rx_draining_ext = 0; int lin; #endif @@ -586,7 +587,11 @@ drain_extension: return -1; } #endif - if (rx_draining_ext && ebuf.len == 0) + if ( +#if !defined(LWS_WITHOUT_EXTENSIONS) + rx_draining_ext && +#endif + ebuf.len == 0) goto already_done; if ( diff --git a/lib/roles/ws/private.h b/lib/roles/ws/private.h index 82eb84b0d08eb52de3b5d8a92163df6349efca2b..71ffcaea966371d95356bf3dbfe729592da8aa41 100644 --- a/lib/roles/ws/private.h +++ b/lib/roles/ws/private.h @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA * - * This is included from private-libwebsockets.h if LWS_ROLE_WS + * This is included from core/private.h if LWS_ROLE_WS */ extern struct lws_role_ops role_ops_ws; diff --git a/lib/roles/ws/server-ws.c b/lib/roles/ws/server-ws.c index 0d8a0b98c303763c6f813a662daf9dce149e164f..62bcd8524f278a22b297f17607c32877ddcc4e12 100644 --- a/lib/roles/ws/server-ws.c +++ b/lib/roles/ws/server-ws.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include <private-libwebsockets.h> +#include <core/private.h> #define LWS_CPYAPP(ptr, str) { strcpy(ptr, str); ptr += strlen(str); } diff --git a/lib/tls/mbedtls/lws-genrsa.c b/lib/tls/mbedtls/lws-genrsa.c index ba5f6d5858e46b08ff4960f80656349f0c245c13..70a9fcf42c0a60553ea4f16e55d65910937a0490 100644 --- a/lib/tls/mbedtls/lws-genrsa.c +++ b/lib/tls/mbedtls/lws-genrsa.c @@ -21,7 +21,7 @@ * lws_genhash provides a hash / hmac abstraction api in lws that works the * same whether you are using openssl or mbedtls hash functions underneath. */ -#include "private-libwebsockets.h" +#include "core/private.h" LWS_VISIBLE void lws_jwk_destroy_genrsa_elements(struct lws_genrsa_elements *el) diff --git a/lib/tls/mbedtls/mbedtls-client.c b/lib/tls/mbedtls/mbedtls-client.c index fd9957b23f26cb439ec0db72f96b1f677aab2097..a7864ab7902a8ab4a308774e74d0ad9c97741a03 100644 --- a/lib/tls/mbedtls/mbedtls-client.c +++ b/lib/tls/mbedtls/mbedtls-client.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" static int OpenSSL_client_verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx) diff --git a/lib/tls/mbedtls/mbedtls-server.c b/lib/tls/mbedtls/mbedtls-server.c index 2a93468df3eda93069771e8e9f01e263e086e97f..12829a37753594488b5f21b94fb63a4aaa5c9e7a 100644 --- a/lib/tls/mbedtls/mbedtls-server.c +++ b/lib/tls/mbedtls/mbedtls-server.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" #include <mbedtls/x509_csr.h> int diff --git a/lib/tls/mbedtls/ssl.c b/lib/tls/mbedtls/ssl.c index b024dfa66a71d49625ea05c76bb8b015e88025a2..6ae9d2556b3ef55d1277d5845f6c400e524adab4 100644 --- a/lib/tls/mbedtls/ssl.c +++ b/lib/tls/mbedtls/ssl.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" #include <mbedtls/oid.h> void diff --git a/lib/tls/openssl/lws-genrsa.c b/lib/tls/openssl/lws-genrsa.c index 3eabe4c3fc31ee93dd98154fa7a37988e512c91f..d04aea87c4ce5f455aed6bc2ea2405f664474bd3 100644 --- a/lib/tls/openssl/lws-genrsa.c +++ b/lib/tls/openssl/lws-genrsa.c @@ -21,7 +21,7 @@ * lws_genhash provides a hash / hmac abstraction api in lws that works the * same whether you are using openssl or mbedtls hash functions underneath. */ -#include "private-libwebsockets.h" +#include "core/private.h" LWS_VISIBLE void lws_jwk_destroy_genrsa_elements(struct lws_genrsa_elements *el) diff --git a/lib/tls/openssl/openssl-client.c b/lib/tls/openssl/openssl-client.c index e1602edaff39b3816186b591d69093b8423bf52b..bff3d40423028a4561e1dbb37d433f4a55e7728b 100644 --- a/lib/tls/openssl/openssl-client.c +++ b/lib/tls/openssl/openssl-client.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" extern int openssl_websocket_private_data_index, openssl_SSL_CTX_private_data_index; diff --git a/lib/tls/openssl/openssl-server.c b/lib/tls/openssl/openssl-server.c index 8a6bf149f17c9d711e0f4d2aa8255166f5fb10e0..a87c920ae0300d649ec24c2627fd722254f6f8fe 100644 --- a/lib/tls/openssl/openssl-server.c +++ b/lib/tls/openssl/openssl-server.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" extern int openssl_websocket_private_data_index, openssl_SSL_CTX_private_data_index; diff --git a/lib/tls/openssl/ssl.c b/lib/tls/openssl/ssl.c index ec43770c405464b313bf2515098bc620e0b9dbf1..0ec554287de3387067106b2a68c73ccbba7858dc 100644 --- a/lib/tls/openssl/ssl.c +++ b/lib/tls/openssl/ssl.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" #include <errno.h> int openssl_websocket_private_data_index, diff --git a/lib/tls/private.h b/lib/tls/private.h index 5c6beeb9e8eac75aad0a50a2ff9a8164133c4cf7..606e2574dc2b7d75a6350794cbce4cdf1e0518f1 100644 --- a/lib/tls/private.h +++ b/lib/tls/private.h @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA * - * This is included from private-libwebsockets.h if LWS_WITH_TLS + * This is included from core/private.h if LWS_WITH_TLS */ #if defined(LWS_WITH_TLS) diff --git a/lib/tls/tls-client.c b/lib/tls/tls-client.c index a122155e2174cadfee5fcdc29d9ba3038066fae5..70eb6f60785d301ecd350be2d5d9f3e692e4c35a 100644 --- a/lib/tls/tls-client.c +++ b/lib/tls/tls-client.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" int lws_ssl_client_connect1(struct lws *wsi) diff --git a/lib/tls/tls-server.c b/lib/tls/tls-server.c index 19549a5d5d2d8fd3a523258a6a02c64ef4209af9..440e790660c5954d1a93fb749ee8800f40ebf11a 100644 --- a/lib/tls/tls-server.c +++ b/lib/tls/tls-server.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" #if defined(LWS_WITH_MBEDTLS) || (defined(OPENSSL_VERSION_NUMBER) && \ OPENSSL_VERSION_NUMBER >= 0x10002000L) diff --git a/lib/tls/tls.c b/lib/tls/tls.c index 916b99f2af00d22ff0722d9c9f79b7a4a861e876..c865c89dcb0c6db1db54c1f317828bf47d916a96 100644 --- a/lib/tls/tls.c +++ b/lib/tls/tls.c @@ -19,7 +19,7 @@ * MA 02110-1301 USA */ -#include "private-libwebsockets.h" +#include "core/private.h" /* * fakes POLLIN on all tls guys with buffered rx diff --git a/minimal-examples/http-server/minimal-http-server-sse-ring/minimal-http-server-sse-ring.c b/minimal-examples/http-server/minimal-http-server-sse-ring/minimal-http-server-sse-ring.c index 802798276f38ec82c3608d1140d07d6df8b2f0b3..616300c6b4b1eaca988c64f722ff79fd1ca51959 100644 --- a/minimal-examples/http-server/minimal-http-server-sse-ring/minimal-http-server-sse-ring.c +++ b/minimal-examples/http-server/minimal-http-server-sse-ring/minimal-http-server-sse-ring.c @@ -120,7 +120,8 @@ wait_unlock: pthread_mutex_unlock(&vhd->lock_ring); /* } ring lock ------- */ wait: - usleep(100000 + (rand() & 0xfffff)); + /* rand() would make more sense but coverity shrieks */ + usleep(100000 + (time(NULL) & 0xffff)); } while (!vhd->finished); diff --git a/test-apps/test-server-libev.c b/test-apps/test-server-libev.c deleted file mode 100644 index 42eca940bbfeca18b1d4af3efe8a41d30d522580..0000000000000000000000000000000000000000 --- a/test-apps/test-server-libev.c +++ /dev/null @@ -1,349 +0,0 @@ -/* - * libwebsockets-test-server - libwebsockets test implementation - * - * Copyright (C) 2011-2018 Andy Green <andy@warmcat.com> - * - * This file is made available under the Creative Commons CC0 1.0 - * Universal Public Domain Dedication. - * - * The person who associated a work with this deed has dedicated - * the work to the public domain by waiving all of his or her rights - * to the work worldwide under copyright law, including all related - * and neighboring rights, to the extent allowed by law. You can copy, - * modify, distribute and perform the work, even for commercial purposes, - * all without asking permission. - * - * The test apps are intended to be adapted for use in your code, which - * may be proprietary. So unlike the library itself, they are licensed - * Public Domain. - */ -#include <libwebsockets.h> -#include <stdio.h> -#include <stdlib.h> -#include <getopt.h> - -int close_testing; -int max_poll_elements; -int debug_level = 7; -volatile int force_exit = 0; -struct lws_context *context; -struct lws_plat_file_ops fops_plat; - -/* http server gets files from this path */ -#define LOCAL_RESOURCE_PATH INSTALL_DATADIR"/libwebsockets-test-server" -char *resource_path = LOCAL_RESOURCE_PATH; - -#if defined(LWS_WITH_TLS) && defined(LWS_HAVE_SSL_CTX_set1_param) -char crl_path[1024] = ""; -#endif - -#define LWS_PLUGIN_STATIC -#include "../plugins/protocol_dumb_increment.c" -#include "../plugins/protocol_lws_mirror.c" -#include "../plugins/protocol_lws_status.c" -#include "../plugins/protocol_post_demo.c" - -/* list of supported protocols and callbacks */ - -static struct lws_protocols protocols[] = { - /* first protocol must always be HTTP handler */ - { "http-only", lws_callback_http_dummy, 0, 0, }, - LWS_PLUGIN_PROTOCOL_DUMB_INCREMENT, - LWS_PLUGIN_PROTOCOL_MIRROR, - LWS_PLUGIN_PROTOCOL_LWS_STATUS, - LWS_PLUGIN_PROTOCOL_POST_DEMO, - { NULL, NULL, 0, 0 } /* terminator */ -}; - -static const struct lws_extension exts[] = { - { - "permessage-deflate", - lws_extension_callback_pm_deflate, - "permessage-deflate; client_no_context_takeover; client_max_window_bits" - }, - { NULL, NULL, NULL /* terminator */ } -}; - -/* - * mount handlers for sections of the URL space - */ - -static const struct lws_http_mount mount_ziptest = { - NULL, /* linked-list pointer to next*/ - "/ziptest", /* mountpoint in URL namespace on this vhost */ - LOCAL_RESOURCE_PATH"/candide.zip", /* handler */ - NULL, /* default filename if none given */ - NULL, - NULL, - NULL, - NULL, - 0, - 0, - 0, - 0, - 0, - 0, - LWSMPRO_FILE, /* origin points to a callback */ - 8, /* strlen("/ziptest"), ie length of the mountpoint */ - NULL, - - { NULL, NULL } // sentinel -}; - -static const struct lws_http_mount mount_post = { - (struct lws_http_mount *)&mount_ziptest, /* linked-list pointer to next*/ - "/formtest", /* mountpoint in URL namespace on this vhost */ - "protocol-post-demo", /* handler */ - NULL, /* default filename if none given */ - NULL, - NULL, - NULL, - NULL, - 0, - 0, - 0, - 0, - 0, - 0, - LWSMPRO_CALLBACK, /* origin points to a callback */ - 9, /* strlen("/formtest"), ie length of the mountpoint */ - NULL, - - { NULL, NULL } // sentinel -}; - -/* - * mount a filesystem directory into the URL space at / - * point it to our /usr/share directory with our assets in - * stuff from here is autoserved by the library - */ - -static const struct lws_http_mount mount = { - (struct lws_http_mount *)&mount_post, /* linked-list pointer to next*/ - "/", /* mountpoint in URL namespace on this vhost */ - LOCAL_RESOURCE_PATH, /* where to go on the filesystem for that */ - "test.html", /* default filename if none given */ - NULL, - NULL, - NULL, - NULL, - 0, - 0, - 0, - 0, - 0, - 0, - LWSMPRO_FILE, /* mount type is a directory in a filesystem */ - 1, /* strlen("/"), ie length of the mountpoint */ - NULL, - - { NULL, NULL } // sentinel -}; - -/* this shows how to override the lws file operations. You don't need - * to do any of this unless you have a reason (eg, want to serve - * compressed files without decompressing the whole archive) - */ -static lws_fop_fd_t -test_server_fops_open(const struct lws_plat_file_ops *fops, - const char *vfs_path, const char *vpath, - lws_fop_flags_t *flags) -{ - lws_fop_fd_t n; - - /* call through to original platform implementation */ - n = fops_plat.open(fops, vfs_path, vpath, flags); - - lwsl_debug("%s: opening %s, ret %p\n", __func__, vfs_path, n); - - return n; -} - -void signal_cb(struct ev_loop *loop, struct ev_signal* watcher, int revents) -{ - lwsl_notice("Signal caught, exiting...\n"); - force_exit = 1; - switch (watcher->signum) { - case SIGTERM: - case SIGINT: - ev_break(loop, EVBREAK_ALL); - break; - default: - signal(SIGABRT, SIG_DFL); - abort(); - break; - } -} - -static struct option options[] = { - { "help", no_argument, NULL, 'h' }, - { "debug", required_argument, NULL, 'd' }, - { "port", required_argument, NULL, 'p' }, - { "ssl", no_argument, NULL, 's' }, - { "allow-non-ssl", no_argument, NULL, 'a' }, - { "interface", required_argument, NULL, 'i' }, - { "closetest", no_argument, NULL, 'c' }, -#ifndef LWS_NO_DAEMONIZE - { "daemonize", no_argument, NULL, 'D' }, -#endif - { "resource_path", required_argument, NULL, 'r' }, - { NULL, 0, 0, 0 } -}; - -int main(int argc, char **argv) -{ - int sigs[] = { SIGINT, SIGKILL, SIGTERM, SIGSEGV, SIGFPE }; - struct ev_signal signals[ARRAY_SIZE(sigs)]; - struct ev_loop *loop = ev_default_loop(0); - struct lws_context_creation_info info; - char interface_name[128] = ""; - const char *iface = NULL; - void *foreign_loops[1]; - char cert_path[1024]; - char key_path[1024]; - int use_ssl = 0; - int opts = 0; - int n = 0; -#ifndef LWS_NO_DAEMONIZE - int daemonize = 0; -#endif - - /* - * take care to zero down the info struct, he contains random garbaage - * from the stack otherwise - */ - memset(&info, 0, sizeof info); - info.port = 7681; - - while (n >= 0) { - n = getopt_long(argc, argv, "ci:hsap:d:Dr:", options, NULL); - if (n < 0) - continue; - switch (n) { -#ifndef LWS_NO_DAEMONIZE - case 'D': - daemonize = 1; - #ifndef _WIN32 - syslog_options &= ~LOG_PERROR; - #endif - break; -#endif - case 'd': - debug_level = atoi(optarg); - break; - case 's': - use_ssl = 1; - break; - case 'a': - opts |= LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT; - break; - case 'p': - info.port = atoi(optarg); - break; - case 'i': - lws_strncpy(interface_name, optarg, sizeof interface_name); - iface = interface_name; - break; - case 'c': - close_testing = 1; - fprintf(stderr, " Close testing mode -- closes on " - "client after 50 dumb increments" - "and suppresses lws_mirror spam\n"); - break; - case 'r': - resource_path = optarg; - printf("Setting resource path to \"%s\"\n", resource_path); - break; - case 'h': - fprintf(stderr, "Usage: test-server " - "[--port=<p>] [--ssl] " - "[-d <log bitfield>] " - "[--resource_path <path>]\n"); - exit(1); - } - } - -#if !defined(LWS_NO_DAEMONIZE) && !defined(WIN32) - /* - * normally lock path would be /var/lock/lwsts or similar, to - * simplify getting started without having to take care about - * permissions or running as root, set to /tmp/.lwsts-lock - */ - if (daemonize && lws_daemonize("/tmp/.lwsts-lock")) { - fprintf(stderr, "Failed to daemonize\n"); - return 1; - } -#endif - - for (n = 0; n < (int)ARRAY_SIZE(sigs); n++) { - ev_init(&signals[n], signal_cb); - ev_signal_set(&signals[n], sigs[n]); - ev_signal_start(loop, &signals[n]); - } - - /* tell the library what debug level to emit and to send it to stderr */ - lws_set_log_level(debug_level, NULL); - - lwsl_notice("libwebsockets test server libev - license LGPL2.1+SLE\n"); - lwsl_notice("(C) Copyright 2010-2018 Andy Green <andy@warmcat.com>\n"); - - printf("Using resource path \"%s\"\n", resource_path); - - info.iface = iface; - info.protocols = protocols; - info.extensions = exts; - info.mounts = &mount; - - info.ssl_cert_filepath = NULL; - info.ssl_private_key_filepath = NULL; - - if (use_ssl) { - if (strlen(resource_path) > sizeof(cert_path) - 32) { - lwsl_err("resource path too long\n"); - return -1; - } - sprintf(cert_path, "%s/libwebsockets-test-server.pem", - resource_path); - if (strlen(resource_path) > sizeof(key_path) - 32) { - lwsl_err("resource path too long\n"); - return -1; - } - sprintf(key_path, "%s/libwebsockets-test-server.key.pem", - resource_path); - - info.ssl_cert_filepath = cert_path; - info.ssl_private_key_filepath = key_path; - - opts |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; - } - info.gid = -1; - info.uid = -1; - info.options = opts | LWS_SERVER_OPTION_LIBEV; - - foreign_loops[0] = &loop; - info.foreign_loops = foreign_loops; - - context = lws_create_context(&info); - if (context == NULL) { - lwsl_err("libwebsocket init failed\n"); - return -1; - } - - /* - * this shows how to override the lws file operations. You don't need - * to do any of this unless you have a reason (eg, want to serve - * compressed files without decompressing the whole archive) - */ - /* stash original platform fops */ - fops_plat = *(lws_get_fops(context)); - /* override the active fops */ - lws_get_fops(context)->open = test_server_fops_open; - - lws_service(context, 0); - - lws_context_destroy(context); - - lwsl_notice("libwebsockets-test-server exited cleanly\n"); - - return 0; -} diff --git a/test-apps/test-server-libevent.c b/test-apps/test-server-libevent.c deleted file mode 100644 index bc47f999d8c7929b59c66fab5d1004d9aef710b6..0000000000000000000000000000000000000000 --- a/test-apps/test-server-libevent.c +++ /dev/null @@ -1,351 +0,0 @@ -/* - * libwebsockets-test-server - libwebsockets test implementation - * - * Copyright (C) 2011-2017 Andy Green <andy@warmcat.com> - * - * This file is made available under the Creative Commons CC0 1.0 - * Universal Public Domain Dedication. - * - * The person who associated a work with this deed has dedicated - * the work to the public domain by waiving all of his or her rights - * to the work worldwide under copyright law, including all related - * and neighboring rights, to the extent allowed by law. You can copy, - * modify, distribute and perform the work, even for commercial purposes, - * all without asking permission. - * - * The test apps are intended to be adapted for use in your code, which - * may be proprietary. So unlike the library itself, they are licensed - * Public Domain. - */ -#include <libwebsockets.h> -#include <stdio.h> -#include <stdlib.h> -#include <getopt.h> - -int close_testing; -int max_poll_elements; -int debug_level = 7; -volatile int force_exit = 0; -struct lws_context *context; -struct lws_plat_file_ops fops_plat; - -/* http server gets files from this path */ -#define LOCAL_RESOURCE_PATH INSTALL_DATADIR"/libwebsockets-test-server" -char *resource_path = LOCAL_RESOURCE_PATH; - -#if defined(LWS_WITH_TLS) && defined(LWS_HAVE_SSL_CTX_set1_param) -char crl_path[1024] = ""; -#endif - -#define LWS_PLUGIN_STATIC -#include "../plugins/protocol_dumb_increment.c" -#include "../plugins/protocol_lws_mirror.c" -#include "../plugins/protocol_lws_status.c" -#include "../plugins/protocol_post_demo.c" - -/* list of supported protocols and callbacks */ - -static struct lws_protocols protocols[] = { - /* first protocol must always be HTTP handler */ - { "http-only", lws_callback_http_dummy, 0, 0, }, - LWS_PLUGIN_PROTOCOL_DUMB_INCREMENT, - LWS_PLUGIN_PROTOCOL_MIRROR, - LWS_PLUGIN_PROTOCOL_LWS_STATUS, - LWS_PLUGIN_PROTOCOL_POST_DEMO, - { NULL, NULL, 0, 0 } /* terminator */ -}; - -static const struct lws_extension exts[] = { - { - "permessage-deflate", - lws_extension_callback_pm_deflate, - "permessage-deflate; client_no_context_takeover; client_max_window_bits" - }, - { NULL, NULL, NULL /* terminator */ } -}; - -/* this shows how to override the lws file operations. You don't need - * to do any of this unless you have a reason (eg, want to serve - * compressed files without decompressing the whole archive) - */ -static lws_fop_fd_t -test_server_fops_open(const struct lws_plat_file_ops *fops, - const char *vfs_path, const char *vpath, - lws_fop_flags_t *flags) -{ - lws_fop_fd_t n; - - /* call through to original platform implementation */ - n = fops_plat.open(fops, vfs_path, vpath, flags); - - lwsl_notice("%s: opening %s, ret %p\n", __func__, vfs_path, n); - - return n; -} - -void signal_cb(evutil_socket_t sock_fd, short events, void *ctx) -{ - struct event_base *event_base_loop = ctx; - - lwsl_notice("Signal caught, exiting...\n"); - force_exit = 1; - if (events & EV_SIGNAL) - event_base_loopbreak(event_base_loop); -} - -/* - * mount handlers for sections of the URL space - */ - -static const struct lws_http_mount mount_ziptest = { - NULL, /* linked-list pointer to next*/ - "/ziptest", /* mountpoint in URL namespace on this vhost */ - LOCAL_RESOURCE_PATH"/candide.zip", /* handler */ - NULL, /* default filename if none given */ - NULL, - NULL, - NULL, - NULL, - 0, - 0, - 0, - 0, - 0, - 0, - LWSMPRO_FILE, /* origin points to a callback */ - 8, /* strlen("/ziptest"), ie length of the mountpoint */ - NULL, - - { NULL, NULL } // sentinel -}; - -static const struct lws_http_mount mount_post = { - (struct lws_http_mount *)&mount_ziptest, /* linked-list pointer to next*/ - "/formtest", /* mountpoint in URL namespace on this vhost */ - "protocol-post-demo", /* handler */ - NULL, /* default filename if none given */ - NULL, - NULL, - NULL, - NULL, - 0, - 0, - 0, - 0, - 0, - 0, - LWSMPRO_CALLBACK, /* origin points to a callback */ - 9, /* strlen("/formtest"), ie length of the mountpoint */ - NULL, - - { NULL, NULL } // sentinel -}; - -/* - * mount a filesystem directory into the URL space at / - * point it to our /usr/share directory with our assets in - * stuff from here is autoserved by the library - */ - -static const struct lws_http_mount mount = { - (struct lws_http_mount *)&mount_post, /* linked-list pointer to next*/ - "/", /* mountpoint in URL namespace on this vhost */ - LOCAL_RESOURCE_PATH, /* where to go on the filesystem for that */ - "test.html", /* default filename if none given */ - NULL, - NULL, - NULL, - NULL, - 0, - 0, - 0, - 0, - 0, - 0, - LWSMPRO_FILE, /* mount type is a directory in a filesystem */ - 1, /* strlen("/"), ie length of the mountpoint */ - NULL, - - { NULL, NULL } // sentinel -}; - -static struct option options[] = { - { "help", no_argument, NULL, 'h' }, - { "debug", required_argument, NULL, 'd' }, - { "port", required_argument, NULL, 'p' }, - { "ssl", no_argument, NULL, 's' }, - { "allow-non-ssl", no_argument, NULL, 'a' }, - { "interface", required_argument, NULL, 'i' }, - { "closetest", no_argument, NULL, 'c' }, - { "libevent", no_argument, NULL, 'e' }, -#ifndef LWS_NO_DAEMONIZE - { "daemonize", no_argument, NULL, 'D' }, -#endif - { "resource_path", required_argument, NULL, 'r' }, - { NULL, 0, 0, 0 } -}; - -int main(int argc, char **argv) -{ - int sigs[] = { SIGINT, SIGKILL, SIGTERM, SIGSEGV, SIGFPE }; - struct event *signals[ARRAY_SIZE(sigs)]; - struct event_base *event_base_loop = event_base_new(); - struct lws_context_creation_info info; - char interface_name[128] = ""; - void *foreign_loops[1]; - const char *iface = NULL; - char cert_path[1024]; - char key_path[1024]; - int use_ssl = 0; - int opts = 0; - int n = 0; -#ifndef LWS_NO_DAEMONIZE - int daemonize = 0; -#endif - - /* - * take care to zero down the info struct, he contains random garbaage - * from the stack otherwise - */ - memset(&info, 0, sizeof info); - info.port = 7681; - - while (n >= 0) { - n = getopt_long(argc, argv, "eci:hsap:d:Dr:", options, NULL); - if (n < 0) - continue; - switch (n) { - case 'e': - opts |= LWS_SERVER_OPTION_LIBEVENT; - break; -#ifndef LWS_NO_DAEMONIZE - case 'D': - daemonize = 1; -#ifndef _WIN32 - syslog_options &= ~LOG_PERROR; -#endif - break; -#endif - case 'd': - debug_level = atoi(optarg); - break; - case 's': - use_ssl = 1; - break; - case 'a': - opts |= LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT; - break; - case 'p': - info.port = atoi(optarg); - break; - case 'i': - lws_strncpy(interface_name, optarg, sizeof interface_name); - iface = interface_name; - break; - case 'c': - close_testing = 1; - fprintf(stderr, " Close testing mode -- closes on " - "client after 50 dumb increments" - "and suppresses lws_mirror spam\n"); - break; - case 'r': - resource_path = optarg; - printf("Setting resource path to \"%s\"\n", resource_path); - break; - case 'h': - fprintf(stderr, "Usage: test-server " - "[--port=<p>] [--ssl] " - "[-d <log bitfield>] " - "[--resource_path <path>]\n"); - exit(1); - } - } - -#if !defined(LWS_NO_DAEMONIZE) && !defined(WIN32) - /* - * normally lock path would be /var/lock/lwsts or similar, to - * simplify getting started without having to take care about - * permissions or running as root, set to /tmp/.lwsts-lock - */ - if (daemonize && lws_daemonize("/tmp/.lwsts-lock")) { - fprintf(stderr, "Failed to daemonize\n"); - return 1; - } -#endif - - for (n = 0; n < (int)ARRAY_SIZE(sigs); n++) { - signals[n] = evsignal_new(event_base_loop, sigs[n], signal_cb, - event_base_loop); - - evsignal_add(signals[n], NULL); - } - - /* tell the library what debug level to emit and to send it to stderr */ - lws_set_log_level(debug_level, NULL); - - lwsl_notice("libwebsockets test server libevent - license LGPL2.1+SLE\n"); - lwsl_notice("(C) Copyright 2010-2018 Andy Green <andy@warmcat.com>\n"); - - printf("Using resource path \"%s\"\n", resource_path); - - info.iface = iface; - info.protocols = protocols; - info.extensions = exts; - info.mounts = &mount; - - info.ssl_cert_filepath = NULL; - info.ssl_private_key_filepath = NULL; - - if (use_ssl) { - if (strlen(resource_path) > sizeof(cert_path) - 32) { - lwsl_err("resource path too long\n"); - return -1; - } - sprintf(cert_path, "%s/libwebsockets-test-server.pem", - resource_path); - if (strlen(resource_path) > sizeof(key_path) - 32) { - lwsl_err("resource path too long\n"); - return -1; - } - sprintf(key_path, "%s/libwebsockets-test-server.key.pem", - resource_path); - - info.ssl_cert_filepath = cert_path; - info.ssl_private_key_filepath = key_path; - - opts |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; - } - info.gid = -1; - info.uid = -1; - info.options = opts | LWS_SERVER_OPTION_LIBEVENT; - - foreign_loops[0] = event_base_loop; - info.foreign_loops = foreign_loops; - - context = lws_create_context(&info); - if (context == NULL) { - lwsl_err("libwebsocket init failed\n"); - return -1; - } - - /* - * this shows how to override the lws file operations. You don't need - * to do any of this unless you have a reason (eg, want to serve - * compressed files without decompressing the whole archive) - */ - /* stash original platform fops */ - fops_plat = *(lws_get_fops(context)); - /* override the active fops */ - lws_get_fops(context)->open = test_server_fops_open; - - event_base_dispatch(event_base_loop); - - for (n = 0; n < (int)ARRAY_SIZE(sigs); n++) - event_free(signals[n]); - - lws_context_destroy(context); - - lwsl_notice("libwebsockets-test-server exited cleanly\n"); - - return 0; -}