diff --git a/CMakeLists.txt b/CMakeLists.txt index 9da7b84c6..372431325 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2517,22 +2517,23 @@ if (LWS_ROLE_WS) create_plugin(protocol_lws_raw_test "" "plugins/protocol_lws_raw_test.c" "" "") - create_plugin(protocol_deaddrop "" - "plugins/deaddrop/protocol_lws_deaddrop.c" "" "") - + if (UNIX AND LWS_HAVE_PTHREAD_H) + create_plugin(protocol_deaddrop "" + "plugins/deaddrop/protocol_lws_deaddrop.c" "" "") + endif() endif() -if (LWS_WITH_SERVER_STATUS) - create_plugin(protocol_lws_server_status "" - "plugins/protocol_lws_server_status.c" "" "") -endif() + if (LWS_WITH_SERVER_STATUS) + create_plugin(protocol_lws_server_status "" + "plugins/protocol_lws_server_status.c" "" "") + endif() -if (NOT LWS_WITHOUT_CLIENT) - create_plugin(protocol_client_loopback_test "" - "plugins/protocol_client_loopback_test.c" "" "") -endif() + if (NOT LWS_WITHOUT_CLIENT) + create_plugin(protocol_client_loopback_test "" + "plugins/protocol_client_loopback_test.c" "" "") + endif() -endif() +endif(LWS_ROLE_WS) create_plugin(protocol_post_demo "" "plugins/protocol_post_demo.c" "" "") diff --git a/READMEs/README.build-windows.md b/READMEs/README.build-windows.md new file mode 100644 index 000000000..677e1f84a --- /dev/null +++ b/READMEs/README.build-windows.md @@ -0,0 +1,75 @@ +# Some notes for the windows jungle + +This was how I compiled libwebsockets in windows March 2020. + +## OpenSSL + +### Installing prebuilt libs + +I used the 1.1.1d (the latest) libs from here, as recommended on the OpenSSL site + +[overbyte.eu](https:..wiki.overbyte.eu/wiki/index.php/ICS_Download#Download_OpenSSL_Binaries_.28required_for_SSL-enabled_components.29) + +I had to use procmon64 (windows' strace) to establish that these libraries are +looking for a cert bundle at "C:\Program Files\Common Files\SSL\cert.pem"... it's not +included in the zip file from the above, so... + +### Installing a cert bundle + +You can get a trusted cert bundle from here + +[drwetter/testssl cert bundle](https://raw.githubusercontent.com/drwetter/testssl.sh/3.1dev/etc/Microsoft.pem) + +Save it into `C:\Program Files\Common Files\SSL\cert.pem` where openssl will be able to see it. + +### Installing cmake + +CMake have a windows installer thing downloadable from here + +[cmake](https://cmake.org/download/) + +after that you can use `cmake` from the terminal OK. + +### Installing git + +Visit the canonical git site to download their windows installer thing + +[git](https://git-scm.com/download/win) + +after that `git` from the terminal is working. + +### Install the free "community" visual studio + +You can do this through "windows store" by searching for "visual studio" + +I installed as little as possible, we just want the C "C++" tools. + +It still wouldn't link without the "mt" helper tool from the +huge windows SDK, so you have to install GB of that as well. + +### Building + +Somehow windows cmake seems slightly broken, some of the plugins and +examples are conditional on `if (NOT WIN32)`, but it configures them +anyway. For this reason (it seems "only", it worked when I commented the +cmake entries for the related plugins) `-DLWS_WITH_MINIMAL_EXAMPLES=1` + +Instead I followed how appveyor builds the stuff in CI... clone libwebsockets then + +``` +> git clone https://libwebsockets.org/repo/libwebsockets +> cd libwebsockets +> mkdir build +> cd build +> cmake .. +> cmake --build . --config DEBUG +``` + +Installing requires admin privs, I opened a second cmd window as admin and did it +there. + +``` +> cmake --install . --config DEBUG +``` + +After that you can run the test apps OK. diff --git a/include/libwebsockets/lws-ring.h b/include/libwebsockets/lws-ring.h index 2343fa264..e642f0f24 100644 --- a/include/libwebsockets/lws-ring.h +++ b/include/libwebsockets/lws-ring.h @@ -277,7 +277,7 @@ lws_ring_dump(struct lws_ring *ring, uint32_t *tail); ___n = 0; \ ___oldest = *(___ptail); \ lws_start_foreach_llp(___type **, ___ppss, ___list_head) { \ - ___m = lws_ring_get_count_waiting_elements( \ + ___m = (int)lws_ring_get_count_waiting_elements( \ ___ring, &(*___ppss)->___mtail); \ if (___m >= ___n) { \ ___n = ___m; \ diff --git a/lib/plat/windows/windows-sockets.c b/lib/plat/windows/windows-sockets.c index fcb31ae85..f3d3ec20b 100644 --- a/lib/plat/windows/windows-sockets.c +++ b/lib/plat/windows/windows-sockets.c @@ -235,7 +235,7 @@ const char * lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt) { WCHAR *buffer; - DWORD bufferlen = cnt; + size_t bufferlen = (size_t)cnt; BOOL ok = FALSE; buffer = lws_malloc(bufferlen * 2, "inet_ntop"); @@ -250,7 +250,9 @@ lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt) srcaddr.sin_family = AF_INET; memcpy(&(srcaddr.sin_addr), src, sizeof(srcaddr.sin_addr)); - if (!WSAAddressToStringW((struct sockaddr*)&srcaddr, sizeof(srcaddr), 0, buffer, &bufferlen)) + if (!WSAAddressToStringW((struct sockaddr*)&srcaddr, + sizeof(srcaddr), 0, buffer, + (LPDWORD)&bufferlen)) ok = TRUE; #ifdef LWS_WITH_IPV6 } else if (af == AF_INET6) { @@ -259,7 +261,9 @@ lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt) srcaddr.sin6_family = AF_INET6; memcpy(&(srcaddr.sin6_addr), src, sizeof(srcaddr.sin6_addr)); - if (!WSAAddressToStringW((struct sockaddr*)&srcaddr, sizeof(srcaddr), 0, buffer, &bufferlen)) + if (!WSAAddressToStringW((struct sockaddr*)&srcaddr, + sizeof(srcaddr), 0, buffer, + (LPDWORD)&bufferlen)) ok = TRUE; #endif } else @@ -269,7 +273,8 @@ lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt) int rv = WSAGetLastError(); lwsl_err("WSAAddressToString() : %d\n", rv); } else { - if (WideCharToMultiByte(CP_ACP, 0, buffer, bufferlen, dst, cnt, 0, NULL) <= 0) + if (WideCharToMultiByte(CP_ACP, 0, buffer, (int)bufferlen, dst, + cnt, 0, NULL) <= 0) ok = FALSE; } @@ -281,7 +286,7 @@ int lws_plat_inet_pton(int af, const char *src, void *dst) { WCHAR *buffer; - DWORD bufferlen = (int)strlen(src) + 1; + size_t bufferlen = strlen(src) + 1; BOOL ok = FALSE; buffer = lws_malloc(bufferlen * 2, "inet_pton"); @@ -290,7 +295,8 @@ lws_plat_inet_pton(int af, const char *src, void *dst) return -1; } - if (MultiByteToWideChar(CP_ACP, 0, src, bufferlen, buffer, bufferlen) <= 0) { + if (MultiByteToWideChar(CP_ACP, 0, src, (int)bufferlen, buffer, + (int)bufferlen) <= 0) { lwsl_err("Failed to convert multi byte to wide char\n"); lws_free(buffer); return -1; diff --git a/lib/roles/http/client/client-handshake.c b/lib/roles/http/client/client-handshake.c index 3cb950ced..be2da3bc9 100644 --- a/lib/roles/http/client/client-handshake.c +++ b/lib/roles/http/client/client-handshake.c @@ -993,10 +993,10 @@ lws_client_reset(struct lws **pwsi, int ssl, const char *address, int port, */ for (n = 0; n < (int)LWS_ARRAY_SIZE(hnames2); n++) - size += lws_hdr_total_length(wsi, hnames2[n]) + 1; + size += lws_hdr_total_length(wsi, hnames2[n]) + (size_t)1; - if ((int)size < lws_hdr_total_length(wsi, _WSI_TOKEN_CLIENT_URI) + 1) - size = lws_hdr_total_length(wsi, _WSI_TOKEN_CLIENT_URI) + 1; + if (size < (size_t)lws_hdr_total_length(wsi, _WSI_TOKEN_CLIENT_URI) + 1) + size = lws_hdr_total_length(wsi, _WSI_TOKEN_CLIENT_URI) + (size_t)1; /* * The incoming address and host can be from inside the existing ah @@ -1022,19 +1022,19 @@ lws_client_reset(struct lws **pwsi, int ssl, const char *address, int port, for (n = 0; n < (int)LWS_ARRAY_SIZE(hnames2); n++) if (lws_hdr_total_length(wsi, hnames2[n])) { - memcpy(p, lws_hdr_simple_ptr(wsi, hnames2[n]), - lws_hdr_total_length(wsi, hnames2[n]) + 1); - p += lws_hdr_total_length(wsi, hnames2[n]) + 1; + memcpy(p, lws_hdr_simple_ptr(wsi, hnames2[n]), (size_t)( + lws_hdr_total_length(wsi, hnames2[n]) + 1)); + p += (size_t)(lws_hdr_total_length(wsi, hnames2[n]) + 1); } else *p++ = '\0'; - memcpy(p, address, strlen(address) + 1); + memcpy(p, address, strlen(address) + (size_t)1); address = p; p += strlen(address) + 1; - memcpy(p, host, strlen(host) + 1); + memcpy(p, host, strlen(host) + (size_t)1); host = p; p += strlen(host) + 1; - memcpy(p, path, strlen(path) + 1); + memcpy(p, path, strlen(path) + (size_t)1); path = p; if (!port) { @@ -1133,11 +1133,12 @@ lws_client_reset(struct lws **pwsi, int ssl, const char *address, int port, for (n = 0; n < (int)LWS_ARRAY_SIZE(hnames2); n++) { if (lws_hdr_simple_create(wsi, hnames2[n], p)) goto bail; - p += lws_hdr_total_length(wsi, hnames2[n]) + 1; + p += lws_hdr_total_length(wsi, hnames2[n]) + (size_t)1; } stash[0] = '/'; - memmove(&stash[1], path, size - 1 < strlen(path) + 1 ? size - 1 : strlen(path) + 1); + memmove(&stash[1], path, size - 1 < strlen(path) + 1 ? + size - 1 : strlen(path) + (size_t)1); if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_URI, stash)) goto bail; diff --git a/minimal-examples/gtk/minimal-gtk/main.c b/minimal-examples/gtk/minimal-gtk/main.c index 00860b489..d88d616f5 100644 --- a/minimal-examples/gtk/minimal-gtk/main.c +++ b/minimal-examples/gtk/minimal-gtk/main.c @@ -130,7 +130,7 @@ static const struct lws_protocols protocols[] = { static gpointer t1_main (gpointer user_data) { - lws_state_notify_link_t notifier = { {}, system_notify_cb, "app" }; + lws_state_notify_link_t notifier = { {0}, system_notify_cb, "app" }; lws_state_notify_link_t *na[] = { ¬ifier, NULL }; GMainContext *t1_mc = (GMainContext *)user_data; struct lws_context_creation_info info; diff --git a/minimal-examples/http-client/minimal-http-client-attach/CMakeLists.txt b/minimal-examples/http-client/minimal-http-client-attach/CMakeLists.txt index b38a68676..96441dac5 100644 --- a/minimal-examples/http-client/minimal-http-client-attach/CMakeLists.txt +++ b/minimal-examples/http-client/minimal-http-client-attach/CMakeLists.txt @@ -76,6 +76,9 @@ MACRO(require_lws_config reqconfig _val result) ENDMACRO() set(requirements 1) +if (WIN32) + set(requirements 0) +endif() require_pthreads(requirements) require_lws_config(LWS_ROLE_H1 1 requirements) require_lws_config(LWS_WITH_CLIENT 1 requirements) diff --git a/minimal-examples/http-client/minimal-http-client-h2-rxflow/minimal-http-client.c b/minimal-examples/http-client/minimal-http-client-h2-rxflow/minimal-http-client.c index 3013ee149..9c9149bc8 100644 --- a/minimal-examples/http-client/minimal-http-client-h2-rxflow/minimal-http-client.c +++ b/minimal-examples/http-client/minimal-http-client-h2-rxflow/minimal-http-client.c @@ -236,7 +236,7 @@ system_notify_cb(lws_state_manager_t *mgr, lws_state_notify_link_t *link, int main(int argc, const char **argv) { - lws_state_notify_link_t notifier = { {}, system_notify_cb, "app" }; + lws_state_notify_link_t notifier = { {0}, system_notify_cb, "app" }; lws_state_notify_link_t *na[] = { ¬ifier, NULL }; struct lws_context_creation_info info; struct lws_context *context; diff --git a/minimal-examples/http-client/minimal-http-client-multi/minimal-http-client-multi.c b/minimal-examples/http-client/minimal-http-client-multi/minimal-http-client-multi.c index 7a326c657..16cb1d0bb 100644 --- a/minimal-examples/http-client/minimal-http-client-multi/minimal-http-client-multi.c +++ b/minimal-examples/http-client/minimal-http-client-multi/minimal-http-client-multi.c @@ -59,7 +59,7 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, { char buf[LWS_PRE + 1024], *start = &buf[LWS_PRE], *p = start, *end = &buf[sizeof(buf) - LWS_PRE - 1]; - int n, idx = (int)(long)lws_get_opaque_user_data(wsi); + int n, idx = (int)(intptr_t)lws_get_opaque_user_data(wsi); struct pss *pss = (struct pss *)user; switch (reason) { @@ -279,7 +279,7 @@ lws_try_client_connection(struct lws_client_connect_info *i, int m) i->path = urlpath; i->pwsi = &client_wsi[m]; - i->opaque_user_data = (void *)(long)m; + i->opaque_user_data = (void *)(intptr_t)m; if (!lws_client_connect_via_info(i)) { failed++; diff --git a/minimal-examples/http-client/minimal-http-client/minimal-http-client.c b/minimal-examples/http-client/minimal-http-client/minimal-http-client.c index c88027a44..fffe8882a 100644 --- a/minimal-examples/http-client/minimal-http-client/minimal-http-client.c +++ b/minimal-examples/http-client/minimal-http-client/minimal-http-client.c @@ -73,7 +73,7 @@ callback_http(struct lws *wsi, enum lws_callback_reasons reason, if (lws_http_basic_auth_gen(ba_user, ba_password, b, sizeof(b))) break; if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_AUTHORIZATION, - (unsigned char *)b, strlen(b), p, end)) + (unsigned char *)b, (int)strlen(b), p, end)) return -1; break; @@ -256,7 +256,7 @@ system_notify_cb(lws_state_manager_t *mgr, lws_state_notify_link_t *link, int main(int argc, const char **argv) { - lws_state_notify_link_t notifier = { {}, system_notify_cb, "app" }; + lws_state_notify_link_t notifier = { {0}, system_notify_cb, "app" }; lws_state_notify_link_t *na[] = { ¬ifier, NULL }; struct lws_context_creation_info info; struct lws_context *context; diff --git a/minimal-examples/ws-server/minimal-ws-server-threads/CMakeLists.txt b/minimal-examples/ws-server/minimal-ws-server-threads/CMakeLists.txt index 076da4fec..5194c70f7 100644 --- a/minimal-examples/ws-server/minimal-ws-server-threads/CMakeLists.txt +++ b/minimal-examples/ws-server/minimal-ws-server-threads/CMakeLists.txt @@ -76,6 +76,9 @@ MACRO(require_lws_config reqconfig _val result) ENDMACRO() set(requirements 1) +if (WIN32) + set(requirements 0) +endif() require_pthreads(requirements) require_lws_config(LWS_ROLE_WS 1 requirements) require_lws_config(LWS_WITH_SERVER 1 requirements)