diff --git a/README.md b/README.md index 851c5b98..0d60a88c 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,10 @@ News ## Lws has the first official ws-over-h2 server support -There's a new standard on the RFC track that enabled multiplexing ws connections +There's a new standard on the RFC track that enables multiplexing ws connections over an http/2 link. Compared to making individual tcp and tls connections for each ws link back to the same server, this makes your site start up radically -faster, and since all the connections are in one tls tunnel, with much memory +faster, and since all the connections are in one tls tunnel, with considerable memory reduction serverside. To enable it on master you just need -DLWS_WITH_HTTP2=1 at cmake. No changes to @@ -22,16 +22,17 @@ apis if you return your own headers, as shown in the test apps for several versi or to take advantage of ws-over-h2. When built with http/2 support, it automatically falls back to http/1 and traditional ws upgrade if that's all the client can handle. -Currently only Chrome Canary v67 supports this ws-over-h2 encapsulation but the other -browsers will catch up soon. +Currently only Chrome Canary v67 supports this ws-over-h2 encapsulation (chrome +must be started with `--enable-websocket-over-http2` switch to enable it currently) +but the other browsers will catch up soon. ## New "minimal examples" https://github.com/warmcat/libwebsockets/tree/master/minimal-examples -These are like the test apps, but focus on doing one thing, the best way, with the minimum amount of code. For example the minimal-http-server serves the cwd on http/1 or http/2 in 50 LOC. +These are like the test apps, but focus on doing one thing, the best way, with the minimum amount of code. For example the minimal-http-server serves the cwd on http/1 or http/2 in 50 LOC. Same thing with tls is just three more lines. -They also build standalone, so it's easier to copy them directly to start your own project; they +They build standalone, so it's easier to copy them directly to start your own project; they are CC0 licensed (public domain) to facilitate that. ## Windows binary builds diff --git a/lib/tls/openssl/openssl-server.c b/lib/tls/openssl/openssl-server.c index ab24af4c..0c7f8c92 100644 --- a/lib/tls/openssl/openssl-server.c +++ b/lib/tls/openssl/openssl-server.c @@ -280,7 +280,7 @@ check_key: if (extra_certs) x = sk_X509_value(extra_certs, 0); else - lwsl_err("%s: no extra certs\n", __func__); + lwsl_info("%s: no extra certs\n", __func__); #endif if (!x) { //lwsl_err("%s: x is NULL\n", __func__); diff --git a/minimal-examples/client-server/minimal-ws-proxy/CMakeLists.txt b/minimal-examples/client-server/minimal-ws-proxy/CMakeLists.txt index 006d260e..c3f7521c 100644 --- a/minimal-examples/client-server/minimal-ws-proxy/CMakeLists.txt +++ b/minimal-examples/client-server/minimal-ws-proxy/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 2.8) -include(CheckSymbolExists) +include(CheckCSourceCompiles) set(SAMP lws-minimal-ws-proxy) set(SRCS minimal-ws-proxy.c) @@ -39,16 +39,17 @@ MACRO(require_lws_config reqconfig _val result) if (LWS_WITH_MINIMAL_EXAMPLES) set(MET ${SAME}) else() - CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) - if (NOT DEFINED HAS) - set(HAS 0) + CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\n#if defined(${reqconfig})\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" HAS_${reqconfig}) + if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig}) + set(HAS_${reqconfig} 0) + else() + set(HAS_${reqconfig} 1) endif() - if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val})) set(MET 1) else() set(MET 0) endif() - endif() if (NOT MET) if (${_val}) diff --git a/minimal-examples/http-client/minimal-http-client/CMakeLists.txt b/minimal-examples/http-client/minimal-http-client/CMakeLists.txt index 511362ed..f8b222cf 100644 --- a/minimal-examples/http-client/minimal-http-client/CMakeLists.txt +++ b/minimal-examples/http-client/minimal-http-client/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 2.8) -include(CheckSymbolExists) +include(CheckCSourceCompiles) set(SAMP lws-minimal-http-client) set(SRCS minimal-http-client.c) @@ -39,16 +39,17 @@ MACRO(require_lws_config reqconfig _val result) if (LWS_WITH_MINIMAL_EXAMPLES) set(MET ${SAME}) else() - CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) - if (NOT DEFINED HAS) - set(HAS 0) + CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\n#if defined(${reqconfig})\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" HAS_${reqconfig}) + if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig}) + set(HAS_${reqconfig} 0) + else() + set(HAS_${reqconfig} 1) endif() - if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val})) set(MET 1) else() set(MET 0) endif() - endif() if (NOT MET) if (${_val}) @@ -61,6 +62,7 @@ MACRO(require_lws_config reqconfig _val result) endif() ENDMACRO() + set(requirements 1) require_lws_config(LWS_WITHOUT_CLIENT 0 requirements) diff --git a/minimal-examples/http-server/README.md b/minimal-examples/http-server/README.md index 59535d8e..034e89d8 100644 --- a/minimal-examples/http-server/README.md +++ b/minimal-examples/http-server/README.md @@ -1,6 +1,7 @@ |Example|Demonstrates| ---|--- -minimal-http-server|Serves a directory over http/1 or http/2, custom 404 handler +minimal-http-server|Serves a directory over http/1, custom 404 handler +minimal-http-server-tls|Serves a directory over http/1 or http/2 with TLS (SSL), custom 404 handler minimal-http-server-libuv|Same as minimal-http-server but libuv event loop minimal-http-server-multivhost|Same as minimal-http-server but three different vhosts minimal-http-server-smp|Multiple service threads diff --git a/minimal-examples/http-server/minimal-http-server-dynamic/CMakeLists.txt b/minimal-examples/http-server/minimal-http-server-dynamic/CMakeLists.txt index 2943e46f..3286a419 100644 --- a/minimal-examples/http-server/minimal-http-server-dynamic/CMakeLists.txt +++ b/minimal-examples/http-server/minimal-http-server-dynamic/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 2.8) -include(CheckSymbolExists) +include(CheckCSourceCompiles) set(SAMP lws-minimal-http-server-dynamic) set(SRCS minimal-http-server-dynamic.c) @@ -39,16 +39,17 @@ MACRO(require_lws_config reqconfig _val result) if (LWS_WITH_MINIMAL_EXAMPLES) set(MET ${SAME}) else() - CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) - if (NOT DEFINED HAS) - set(HAS 0) + CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\n#if defined(${reqconfig})\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" HAS_${reqconfig}) + if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig}) + set(HAS_${reqconfig} 0) + else() + set(HAS_${reqconfig} 1) endif() - if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val})) set(MET 1) else() set(MET 0) endif() - endif() if (NOT MET) if (${_val}) diff --git a/minimal-examples/http-server/minimal-http-server-libuv/CMakeLists.txt b/minimal-examples/http-server/minimal-http-server-libuv/CMakeLists.txt index 3a2a0e5a..dc56dcdd 100644 --- a/minimal-examples/http-server/minimal-http-server-libuv/CMakeLists.txt +++ b/minimal-examples/http-server/minimal-http-server-libuv/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 2.8) -include(CheckSymbolExists) +include(CheckCSourceCompiles) set(SAMP lws-minimal-http-server-libuv) set(SRCS minimal-http-server.c) @@ -39,16 +39,17 @@ MACRO(require_lws_config reqconfig _val result) if (LWS_WITH_MINIMAL_EXAMPLES) set(MET ${SAME}) else() - CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) - if (NOT DEFINED HAS) - set(HAS 0) + CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\n#if defined(${reqconfig})\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" HAS_${reqconfig}) + if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig}) + set(HAS_${reqconfig} 0) + else() + set(HAS_${reqconfig} 1) endif() - if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val})) set(MET 1) else() set(MET 0) endif() - endif() if (NOT MET) if (${_val}) diff --git a/minimal-examples/http-server/minimal-http-server-multivhost/CMakeLists.txt b/minimal-examples/http-server/minimal-http-server-multivhost/CMakeLists.txt index 5684ff2f..ae0400dd 100644 --- a/minimal-examples/http-server/minimal-http-server-multivhost/CMakeLists.txt +++ b/minimal-examples/http-server/minimal-http-server-multivhost/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 2.8) -include(CheckSymbolExists) +include(CheckCSourceCompiles) set(SAMP lws-minimal-http-server-multivhost) set(SRCS minimal-http-server.c) @@ -39,16 +39,17 @@ MACRO(require_lws_config reqconfig _val result) if (LWS_WITH_MINIMAL_EXAMPLES) set(MET ${SAME}) else() - CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) - if (NOT DEFINED HAS) - set(HAS 0) + CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\n#if defined(${reqconfig})\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" HAS_${reqconfig}) + if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig}) + set(HAS_${reqconfig} 0) + else() + set(HAS_${reqconfig} 1) endif() - if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val})) set(MET 1) else() set(MET 0) endif() - endif() if (NOT MET) if (${_val}) @@ -60,7 +61,6 @@ MACRO(require_lws_config reqconfig _val result) endif() ENDMACRO() - set(requirements 1) require_lws_config(LWS_WITHOUT_SERVER 0 requirements) diff --git a/minimal-examples/http-server/minimal-http-server-smp/CMakeLists.txt b/minimal-examples/http-server/minimal-http-server-smp/CMakeLists.txt index 59f49b75..fedd1550 100644 --- a/minimal-examples/http-server/minimal-http-server-smp/CMakeLists.txt +++ b/minimal-examples/http-server/minimal-http-server-smp/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 2.8) include(CheckIncludeFile) -include(CheckSymbolExists) +include(CheckCSourceCompiles) set(SAMP lws-minimal-http-server-smp) set(SRCS minimal-http-server-smp.c) @@ -51,16 +51,17 @@ MACRO(require_lws_config reqconfig _val result) if (LWS_WITH_MINIMAL_EXAMPLES) set(MET ${SAME}) else() - CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) - if (NOT DEFINED HAS) - set(HAS 0) + CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\n#if defined(${reqconfig})\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" HAS_${reqconfig}) + if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig}) + set(HAS_${reqconfig} 0) + else() + set(HAS_${reqconfig} 1) endif() - if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val})) set(MET 1) else() set(MET 0) endif() - endif() if (NOT MET) if (${_val}) diff --git a/minimal-examples/http-server/minimal-http-server-tls/CMakeLists.txt b/minimal-examples/http-server/minimal-http-server-tls/CMakeLists.txt new file mode 100644 index 00000000..7c8e7d62 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-tls/CMakeLists.txt @@ -0,0 +1,78 @@ +cmake_minimum_required(VERSION 2.8) +include(CheckCSourceCompiles) + +set(SAMP lws-minimal-http-server-tls) +set(SRCS minimal-http-server-tls.c) + +# If we are being built as part of lws, confirm current build config supports +# reqconfig, else skip building ourselves. +# +# If we are being built externally, confirm installed lws was configured to +# support reqconfig, else error out with a helpful message about the problem. +# +MACRO(require_lws_config reqconfig _val result) + + if (DEFINED ${reqconfig}) + if (${reqconfig}) + set (rq 1) + else() + set (rq 0) + endif() + else() + set(rq 0) + endif() + + if (${_val} EQUAL ${rq}) + set(SAME 1) + else() + set(SAME 0) + endif() + + if (LWS_WITH_MINIMAL_EXAMPLES AND NOT ${SAME}) + if (${_val}) + message("${SAMP}: skipping as lws being built without ${reqconfig}") + else() + message("${SAMP}: skipping as lws built with ${reqconfig}") + endif() + set(${result} 0) + else() + if (LWS_WITH_MINIMAL_EXAMPLES) + set(MET ${SAME}) + else() + CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\n#if defined(${reqconfig})\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" HAS_${reqconfig}) + if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig}) + set(HAS_${reqconfig} 0) + else() + set(HAS_${reqconfig} 1) + endif() + if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val})) + set(MET 1) + else() + set(MET 0) + endif() + endif() + if (NOT MET) + if (${_val}) + message(FATAL_ERROR "This project requires lws must have been configured with ${reqconfig}") + else() + message(FATAL_ERROR "Lws configuration of ${reqconfig} is incompatible with this project") + endif() + endif() + + endif() +ENDMACRO() + +set(requirements 1) +require_lws_config(LWS_WITHOUT_SERVER 0 requirements) +require_lws_config(LWS_OPENSSL_SUPPORT 1 requirements) + +if (requirements) + add_executable(${SAMP} ${SRCS}) + + if (websockets_shared) + target_link_libraries(${SAMP} websockets_shared) + add_dependencies(${SAMP} websockets_shared) + else() + target_link_libraries(${SAMP} websockets) + endif() +endif() diff --git a/minimal-examples/http-server/minimal-http-server-tls/README.md b/minimal-examples/http-server/minimal-http-server-tls/README.md new file mode 100644 index 00000000..b10ffed6 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-tls/README.md @@ -0,0 +1,45 @@ +# lws minimal http server with tls + +## build + +``` + $ cmake . && make +``` + +## usage + +``` + $ ./lws-minimal-http-server-tls +[2018/03/20 13:23:13:0131] USER: LWS minimal http server TLS | visit https://localhost:7681 +[2018/03/20 13:23:13:0142] NOTICE: Creating Vhost 'default' port 7681, 1 protocols, IPv6 off +[2018/03/20 13:23:13:0142] NOTICE: Using SSL mode +[2018/03/20 13:23:13:0146] NOTICE: SSL ECDH curve 'prime256v1' +[2018/03/20 13:23:13:0146] NOTICE: HTTP2 / ALPN enabled +[2018/03/20 13:23:13:0195] NOTICE: lws_tls_client_create_vhost_context: doing cert filepath localhost-100y.cert +[2018/03/20 13:23:13:0195] NOTICE: Loaded client cert localhost-100y.cert +[2018/03/20 13:23:13:0195] NOTICE: lws_tls_client_create_vhost_context: doing private key filepath +[2018/03/20 13:23:13:0196] NOTICE: Loaded client cert private key localhost-100y.key +[2018/03/20 13:23:13:0196] NOTICE: created client ssl context for default +[2018/03/20 13:23:14:0207] NOTICE: vhost default: cert expiry: 730459d +``` + +Visit https://localhost:7681 + +Because it uses a selfsigned certificate, you will have to make an exception for it in your browser. + +## Certificate creation + +The selfsigned certs provided were created with + +``` +echo -e "GB\nErewhon\nAll around\nlibwebsockets-test\n\nlocalhost\nnone@invalid.org\n" | openssl req -new -newkey rsa:4096 -days 36500 -nodes -x509 -keyout "localhost-100y.key" -out "localhost-100y.cert" +``` + +they cover "localhost" and last 100 years from 2018-03-20. + +You can replace them with commercial certificates matching your hostname. + +## HTTP/2 + +If you built lws with `-DLWS_WITH_HTTP2=1` at cmake, this simple server is also http/2 capable +out of the box. If the index.html was loaded over http/2, it will display an HTTP 2 png. diff --git a/minimal-examples/http-server/minimal-http-server-tls/localhost-100y.cert b/minimal-examples/http-server/minimal-http-server-tls/localhost-100y.cert new file mode 100644 index 00000000..6f372db4 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-tls/localhost-100y.cert @@ -0,0 +1,34 @@ +-----BEGIN CERTIFICATE----- +MIIF5jCCA86gAwIBAgIJANq50IuwPFKgMA0GCSqGSIb3DQEBCwUAMIGGMQswCQYD +VQQGEwJHQjEQMA4GA1UECAwHRXJld2hvbjETMBEGA1UEBwwKQWxsIGFyb3VuZDEb +MBkGA1UECgwSbGlid2Vic29ja2V0cy10ZXN0MRIwEAYDVQQDDAlsb2NhbGhvc3Qx +HzAdBgkqhkiG9w0BCQEWEG5vbmVAaW52YWxpZC5vcmcwIBcNMTgwMzIwMDQxNjA3 +WhgPMjExODAyMjQwNDE2MDdaMIGGMQswCQYDVQQGEwJHQjEQM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hlhT2RUFRdeRUJD0IxrH/hkvb6myHHnK8nOYezFPjUlmRKUgNEDuA +xbnXZzPdCRNV9V2mShbXvCyiDY7WCQE2Bn44z26O0uWVk+7DNNLH9BnkwUtOnM9P +wtmD9phWexm4q2GnTsiL6Ul6cy0QlTJWKVLEUQQ6yda582e23J1AXqtqFcpfoE34 +H3afEiGy882b+ZBiwkeV+oq6XVF8sFyr9zYrv9CvWTYlkpTQfLTZSsgPdEHYVcjv +xQ2D+XyDR0aRLRlvxUa9dHGFHLICG34Juq5Ai6lM1EsoD8HSsJpMcmrH7MWw2cKk +ujC3rMdFTtte83wF1uuF4FjUC72+SmcQN7A386BC/nk2TTsJawTDzqwOu/VdZv2g +1WpTHlumlClZeP+G/jkSyDwqNnTu1aodDmUa4xZodfhP1HWPwUKFcq8oQr148QYA +AOlbUOJQU7QwRWd1VbnwhDtQWXC92A2w1n/xkZSR1BM/NUSDhkBSUU1WjMbWg6Gg +mnIZLRerQCu1Oozr87rOQqQakPkyt8BUSNK3K42j2qcfhAONdRl8Hq8Qs5pupy+s +8sdCGDlwR3JNCMv6u48OK87F4mcIxhkSefFJUFII25pCGN5WtE4p5l+9cnO1GrIX +e2Hl/7M0c/lbZ4FvXgARlex2rkgS0Ka06HE= +-----END CERTIFICATE----- diff --git a/minimal-examples/http-server/minimal-http-server-tls/localhost-100y.key b/minimal-examples/http-server/minimal-http-server-tls/localhost-100y.key new file mode 100644 index 00000000..148f8598 --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-tls/localhost-100y.key @@ -0,0 +1,52 @@ +-----BEGIN PRIVATE KEY----- +MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQCjYtuWaICCY0tJ +PubxpIgIL+WWmz/fmK8IQr11Wtee6/IUyUlo5I602mq1qcLhT/kmpoR8Di3DAmHK +nSWdPWtn1BtXLErLlUiHgZDrZWInmEBjKM1DZf+CvNGZ+EzPgBv5nTekLWcfI5ZZ +toGuIP1Dl/IkNDw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uTLDqw8bChq7O5y6yfuWaOWvL7nxI8NvSsfj4y635gIa/0dFeBYZEfHI +UlGdNVomwXwYEzgE/c19ruIowX7HU/NgxMWTMZhpazlxgesXybel+YNcfDQ4e3RM +OMz3ZFiaMaJsGGNf4++d9TmMgk4Ns6oDs6Tb9AECggEBAJYzd+SOYo26iBu3nw3L +65uEeh6xou8pXH0Tu4gQrPQTRZZ/nT3iNgOwqu1gRuxcq7TOjt41UdqIKO8vN7/A +aJavCpaKoIMowy/aGCbvAvjNPpU3unU8jdl/t08EXs79S5IKPcgAx87sTTi7KDN5 +SYt4tr2uPEe53NTXuSatilG5QCyExIELOuzWAMKzg7CAiIlNS9foWeLyVkBgCQ6S +me/L8ta+mUDy37K6vC34jh9vK9yrwF6X44ItRoOJafCaVfGI+175q/eWcqTX4q+I +G4tKls4sL4mgOJLq+ra50aYMxbcuommctPMXU6CrrYyQpPTHMNVDQy2ttFdsq9iK +TncCggEBAMmt/8yvPflS+xv3kg/ZBvR9JB1In2n3rUCYYD47ReKFqJ03Vmq5C9nY +56s9w7OUO8perBXlJYmKZQhO4293lvxZD2Iq4NcZbVSCMoHAUzhzY3brdgtSIxa2 +gGveGAezZ38qKIU26dkz7deECY4vrsRkwhpTW0LGVCpjcQoaKvymAoCmAs8V2oMr +Ziw1YQ9uOUoWwOqm1wZqmVcOXvPIS2gWAs3fQlWjH9hkcQTMsUaXQDOD0aqkSY3E +NqOvbCV1/oUpRi3076khCoAXI1bKSn/AvR3KDP14B5toHI/F5OTSEiGhhHesgRrs +fBrpEY1IATtPq1taBZZogRqI3rOkkPk= +-----END PRIVATE KEY----- diff --git a/minimal-examples/http-server/minimal-http-server-tls/minimal-http-server-tls.c b/minimal-examples/http-server/minimal-http-server-tls/minimal-http-server-tls.c new file mode 100644 index 00000000..7afd0ffd --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-tls/minimal-http-server-tls.c @@ -0,0 +1,84 @@ +/* + * lws-minimal-http-server-tls + * + * Copyright (C) 2018 Andy Green + * + * This file is made available under the Creative Commons CC0 1.0 + * Universal Public Domain Dedication. + * + * This demonstrates the most minimal http server you can make with lws, + * with three extra lines giving it tls (ssl) capabilities, which in + * turn allow operation with HTTP/2 if lws was configured for it. + * + * To keep it simple, it serves stuff from the subdirectory + * "./mount-origin" of the directory it was started in. + * + * You can change that by changing mount.origin below. + */ + +#include +#include +#include + +static int interrupted; + +static const struct lws_http_mount mount = { + /* .mount_next */ NULL, /* linked-list "next" */ + /* .mountpoint */ "/", /* mountpoint URL */ + /* .origin */ "./mount-origin", /* serve from dir */ + /* .def */ "index.html", /* default filename */ + /* .protocol */ NULL, + /* .cgienv */ NULL, + /* .extra_mimetypes */ NULL, + /* .interpret */ NULL, + /* .cgi_timeout */ 0, + /* .cache_max_age */ 0, + /* .auth_mask */ 0, + /* .cache_reusable */ 0, + /* .cache_revalidate */ 0, + /* .cache_intermediaries */ 0, + /* .origin_protocol */ LWSMPRO_FILE, /* files in a dir */ + /* .mountpoint_len */ 1, /* char count */ + /* .basic_auth_login_file */ NULL, +}; + +void sigint_handler(int sig) +{ + interrupted = 1; +} + +int main(int argc, char **argv) +{ + struct lws_context_creation_info info; + struct lws_context *context; + int n = 0; + + signal(SIGINT, sigint_handler); + + memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */ + info.port = 7681; + info.mounts = &mount; + info.error_document_404 = "/404.html"; + + info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info.ssl_cert_filepath = "localhost-100y.cert"; + info.ssl_private_key_filepath = "localhost-100y.key"; + + lws_set_log_level(LLL_ERR | LLL_WARN | LLL_NOTICE | LLL_USER + /* | LLL_INFO */ /* | LLL_DEBUG */, NULL); + + lwsl_user("LWS minimal http server TLS | visit https://localhost:7681\n"); + + context = lws_create_context(&info); + if (!context) { + lwsl_err("lws init failed\n"); + return 1; + } + + while (n >= 0 && !interrupted) + n = lws_service(context, 1000); + + lws_context_destroy(context); + + return 0; +} diff --git a/minimal-examples/http-server/minimal-http-server-tls/mount-origin/404.html b/minimal-examples/http-server/minimal-http-server-tls/mount-origin/404.html new file mode 100644 index 00000000..1f7ae66e --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-tls/mount-origin/404.html @@ -0,0 +1,9 @@ + + + +
+

404

+ Sorry, that file doesn't exist. + + + diff --git a/minimal-examples/http-server/minimal-http-server-tls/mount-origin/favicon.ico b/minimal-examples/http-server/minimal-http-server-tls/mount-origin/favicon.ico new file mode 100644 index 00000000..c0cc2e3d Binary files /dev/null and b/minimal-examples/http-server/minimal-http-server-tls/mount-origin/favicon.ico differ diff --git a/minimal-examples/http-server/minimal-http-server-tls/mount-origin/http2.png b/minimal-examples/http-server/minimal-http-server-tls/mount-origin/http2.png new file mode 100644 index 00000000..439bfa48 Binary files /dev/null and b/minimal-examples/http-server/minimal-http-server-tls/mount-origin/http2.png differ diff --git a/minimal-examples/http-server/minimal-http-server-tls/mount-origin/index.html b/minimal-examples/http-server/minimal-http-server-tls/mount-origin/index.html new file mode 100644 index 00000000..d245a57d --- /dev/null +++ b/minimal-examples/http-server/minimal-http-server-tls/mount-origin/index.html @@ -0,0 +1,39 @@ + + + +
+ + Hello from the minimal https server example. +
+ You can confirm the 404 page handler by going to this + nonexistant page. +
+
+ + + + + diff --git a/minimal-examples/http-server/minimal-http-server-tls/mount-origin/libwebsockets.org-logo.png b/minimal-examples/http-server/minimal-http-server-tls/mount-origin/libwebsockets.org-logo.png new file mode 100644 index 00000000..2060a10c Binary files /dev/null and b/minimal-examples/http-server/minimal-http-server-tls/mount-origin/libwebsockets.org-logo.png differ diff --git a/minimal-examples/http-server/minimal-http-server/CMakeLists.txt b/minimal-examples/http-server/minimal-http-server/CMakeLists.txt index 457e817a..a17d4e9f 100644 --- a/minimal-examples/http-server/minimal-http-server/CMakeLists.txt +++ b/minimal-examples/http-server/minimal-http-server/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 2.8) -include(CheckSymbolExists) +include(CheckCSourceCompiles) set(SAMP lws-minimal-http-server) set(SRCS minimal-http-server.c) @@ -39,16 +39,17 @@ MACRO(require_lws_config reqconfig _val result) if (LWS_WITH_MINIMAL_EXAMPLES) set(MET ${SAME}) else() - CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) - if (NOT DEFINED HAS) - set(HAS 0) + CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\n#if defined(${reqconfig})\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" HAS_${reqconfig}) + if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig}) + set(HAS_${reqconfig} 0) + else() + set(HAS_${reqconfig} 1) endif() - if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val})) set(MET 1) else() set(MET 0) endif() - endif() if (NOT MET) if (${_val}) @@ -61,6 +62,7 @@ MACRO(require_lws_config reqconfig _val result) endif() ENDMACRO() + set(requirements 1) require_lws_config(LWS_WITHOUT_SERVER 0 requirements) diff --git a/minimal-examples/ws-client/minimal-ws-client-rx/CMakeLists.txt b/minimal-examples/ws-client/minimal-ws-client-rx/CMakeLists.txt index 22f69014..9548db3c 100644 --- a/minimal-examples/ws-client/minimal-ws-client-rx/CMakeLists.txt +++ b/minimal-examples/ws-client/minimal-ws-client-rx/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 2.8) -include(CheckSymbolExists) +include(CheckCSourceCompiles) set(SAMP lws-minimal-ws-client-rx) set(SRCS minimal-ws-client.c) @@ -39,16 +39,17 @@ MACRO(require_lws_config reqconfig _val result) if (LWS_WITH_MINIMAL_EXAMPLES) set(MET ${SAME}) else() - CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) - if (NOT DEFINED HAS) - set(HAS 0) + CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\n#if defined(${reqconfig})\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" HAS_${reqconfig}) + if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig}) + set(HAS_${reqconfig} 0) + else() + set(HAS_${reqconfig} 1) endif() - if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val})) set(MET 1) else() set(MET 0) endif() - endif() if (NOT MET) if (${_val}) diff --git a/minimal-examples/ws-client/minimal-ws-client-tx/CMakeLists.txt b/minimal-examples/ws-client/minimal-ws-client-tx/CMakeLists.txt index 156d7c35..a43e3dc6 100644 --- a/minimal-examples/ws-client/minimal-ws-client-tx/CMakeLists.txt +++ b/minimal-examples/ws-client/minimal-ws-client-tx/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 2.8) include(CheckIncludeFile) -include(CheckSymbolExists) +include(CheckCSourceCompiles) set(SAMP lws-minimal-ws-client-tx) set(SRCS minimal-ws-client.c) @@ -50,16 +50,17 @@ MACRO(require_lws_config reqconfig _val result) if (LWS_WITH_MINIMAL_EXAMPLES) set(MET ${SAME}) else() - CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) - if (NOT DEFINED HAS) - set(HAS 0) + CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\n#if defined(${reqconfig})\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" HAS_${reqconfig}) + if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig}) + set(HAS_${reqconfig} 0) + else() + set(HAS_${reqconfig} 1) endif() - if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val})) set(MET 1) else() set(MET 0) endif() - endif() if (NOT MET) if (${_val}) diff --git a/minimal-examples/ws-server/minimal-ws-broker/CMakeLists.txt b/minimal-examples/ws-server/minimal-ws-broker/CMakeLists.txt index 8ad44309..73fb25a8 100644 --- a/minimal-examples/ws-server/minimal-ws-broker/CMakeLists.txt +++ b/minimal-examples/ws-server/minimal-ws-broker/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 2.8) -include(CheckSymbolExists) +include(CheckCSourceCompiles) set(SAMP lws-minimal-ws-broker) set(SRCS minimal-ws-broker.c) @@ -39,16 +39,17 @@ MACRO(require_lws_config reqconfig _val result) if (LWS_WITH_MINIMAL_EXAMPLES) set(MET ${SAME}) else() - CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) - if (NOT DEFINED HAS) - set(HAS 0) + CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\n#if defined(${reqconfig})\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" HAS_${reqconfig}) + if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig}) + set(HAS_${reqconfig} 0) + else() + set(HAS_${reqconfig} 1) endif() - if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val})) set(MET 1) else() set(MET 0) endif() - endif() if (NOT MET) if (${_val}) @@ -60,7 +61,6 @@ MACRO(require_lws_config reqconfig _val result) endif() ENDMACRO() - set(requirements 1) require_lws_config(LWS_WITHOUT_SERVER 0 requirements) diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/CMakeLists.txt b/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/CMakeLists.txt index 36af4b78..82b70652 100644 --- a/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/CMakeLists.txt +++ b/minimal-examples/ws-server/minimal-ws-server-pmd-bulk/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 2.8.9) -include(CheckSymbolExists) +include(CheckCSourceCompiles) set(SAMP lws-minimal-ws-server-pmd-bulk) set(SRCS minimal-ws-server-pmd-bulk.c) @@ -39,16 +39,17 @@ MACRO(require_lws_config reqconfig _val result) if (LWS_WITH_MINIMAL_EXAMPLES) set(MET ${SAME}) else() - CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) - if (NOT DEFINED HAS) - set(HAS 0) + CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\n#if defined(${reqconfig})\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" HAS_${reqconfig}) + if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig}) + set(HAS_${reqconfig} 0) + else() + set(HAS_${reqconfig} 1) endif() - if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val})) set(MET 1) else() set(MET 0) endif() - endif() if (NOT MET) if (${_val}) diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd/CMakeLists.txt b/minimal-examples/ws-server/minimal-ws-server-pmd/CMakeLists.txt index 8b9721b1..fb607abf 100644 --- a/minimal-examples/ws-server/minimal-ws-server-pmd/CMakeLists.txt +++ b/minimal-examples/ws-server/minimal-ws-server-pmd/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 2.8.9) -include(CheckSymbolExists) +include(CheckCSourceCompiles) set(SAMP lws-minimal-ws-server-pmd) set(SRCS minimal-ws-server-pmd.c) @@ -39,16 +39,17 @@ MACRO(require_lws_config reqconfig _val result) if (LWS_WITH_MINIMAL_EXAMPLES) set(MET ${SAME}) else() - CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) - if (NOT DEFINED HAS) - set(HAS 0) + CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\n#if defined(${reqconfig})\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" HAS_${reqconfig}) + if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig}) + set(HAS_${reqconfig} 0) + else() + set(HAS_${reqconfig} 1) endif() - if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val})) set(MET 1) else() set(MET 0) endif() - endif() if (NOT MET) if (${_val}) diff --git a/minimal-examples/ws-server/minimal-ws-server-ring/CMakeLists.txt b/minimal-examples/ws-server/minimal-ws-server-ring/CMakeLists.txt index 04e9d5bd..01445cf0 100644 --- a/minimal-examples/ws-server/minimal-ws-server-ring/CMakeLists.txt +++ b/minimal-examples/ws-server/minimal-ws-server-ring/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 2.8) -include(CheckSymbolExists) +include(CheckCSourceCompiles) set(SAMP lws-minimal-ws-server-ring) set(SRCS minimal-ws-server.c) @@ -39,16 +39,17 @@ MACRO(require_lws_config reqconfig _val result) if (LWS_WITH_MINIMAL_EXAMPLES) set(MET ${SAME}) else() - CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) - if (NOT DEFINED HAS) - set(HAS 0) + CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\n#if defined(${reqconfig})\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" HAS_${reqconfig}) + if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig}) + set(HAS_${reqconfig} 0) + else() + set(HAS_${reqconfig} 1) endif() - if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val})) set(MET 1) else() set(MET 0) endif() - endif() if (NOT MET) if (${_val}) 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 8b147749..4f232053 100644 --- a/minimal-examples/ws-server/minimal-ws-server-threads/CMakeLists.txt +++ b/minimal-examples/ws-server/minimal-ws-server-threads/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 2.8) include(CheckIncludeFile) -include(CheckSymbolExists) +include(CheckCSourceCompiles) set(SAMP lws-minimal-ws-server-threads) set(SRCS minimal-ws-server.c) @@ -51,16 +51,17 @@ MACRO(require_lws_config reqconfig _val result) if (LWS_WITH_MINIMAL_EXAMPLES) set(MET ${SAME}) else() - CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) - if (NOT DEFINED HAS) - set(HAS 0) + CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\n#if defined(${reqconfig})\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" HAS_${reqconfig}) + if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig}) + set(HAS_${reqconfig} 0) + else() + set(HAS_${reqconfig} 1) endif() - if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val})) set(MET 1) else() set(MET 0) endif() - endif() if (NOT MET) if (${_val}) diff --git a/minimal-examples/ws-server/minimal-ws-server/CMakeLists.txt b/minimal-examples/ws-server/minimal-ws-server/CMakeLists.txt index 6ec72fe9..c0cb7cbc 100644 --- a/minimal-examples/ws-server/minimal-ws-server/CMakeLists.txt +++ b/minimal-examples/ws-server/minimal-ws-server/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 2.8) -include(CheckSymbolExists) +include(CheckCSourceCompiles) set(SAMP lws-minimal-ws-server) set(SRCS minimal-ws-server.c) @@ -39,16 +39,17 @@ MACRO(require_lws_config reqconfig _val result) if (LWS_WITH_MINIMAL_EXAMPLES) set(MET ${SAME}) else() - CHECK_SYMBOL_EXISTS(${reqconfig} libwebsockets.h HAS) - if (NOT DEFINED HAS) - set(HAS 0) + CHECK_C_SOURCE_COMPILES("#include \nint main(void) {\n#if defined(${reqconfig})\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" HAS_${reqconfig}) + if (NOT DEFINED HAS_${reqconfig} OR NOT HAS_${reqconfig}) + set(HAS_${reqconfig} 0) + else() + set(HAS_${reqconfig} 1) endif() - if ((HAS AND ${_val}) OR (NOT HAS AND NOT ${_val})) + if ((HAS_${reqconfig} AND ${_val}) OR (NOT HAS_${reqconfig} AND NOT ${_val})) set(MET 1) else() set(MET 0) endif() - endif() if (NOT MET) if (${_val})